Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Misc ozCore++

- ozCore
  * Buffer::Buffer(const String&), toString(), resize()
  * File::read(char*, int*), readString(), writeString()
  * JSON:
    + iterators for arrays
    + C++-style comments allowed
- cmake
  * OZ_TESTS
  • Loading branch information...
commit c83e8e7043ce0b495e641a35e32f11b9e25ec50a 1 parent 53d836f
@ducakar authored
View
1  CMakeLists.txt
@@ -19,6 +19,7 @@ option( OZ_GL_ES "Use OpenGL ES 2.0 instead of OpenGL 2.1+." OFF )
option( OZ_NONFREE "Enable support for building S3TC textures." OFF )
option( OZ_STANDALONE "Install layout appropriate for launching from its own folder." OFF )
+option( OZ_TESTS "Build test programs (that should only be used by me)." OFF )
#
# Internal configuration
View
2  ChangeLog.md
@@ -19,6 +19,8 @@
- ozDynamics
* collision
+ primitives: Box, Capsule, Mesh, Compound
+- matrix
+ * melee attack
- ui
* UI colours, fonts and layouts can be configured in `ui/style.json`
- client
View
2  src/client/Mesh.cc
@@ -261,7 +261,7 @@ void Mesh::upload( const Vertex* vertices, int nVertices, uint usage ) const
glBindBuffer( GL_ARRAY_BUFFER, 0 );
}
-void Mesh::load( oz::InputStream* istream, oz::uint usage )
+void Mesh::load( oz::InputStream* istream, uint usage )
{
flags = 0;
View
4 src/client/ui/Inventory.cc
@@ -149,7 +149,7 @@ void Inventory::drawComponent( int height, const Object* container, int tagged,
}
}
}
-slotsRendered:
+ slotsRendered:
int nScrollRows = max( 0, containerClazz->nItems - ( ROWS - 1 ) * COLS - 1 ) / COLS;
@@ -252,7 +252,7 @@ void Inventory::drawComponent( int height, const Object* container, int tagged,
shape.fill( x + width - ICON_SIZE - 4, y + height - FOOTER_SIZE + 4, ICON_SIZE, ICON_SIZE );
glBindTexture( GL_TEXTURE_2D, shader.defaultTexture );
}
-noIcon:
+ noIcon:
if( tagged != cachedTaggedItemIndex ) {
cachedTaggedItemIndex = tagged;
View
11 src/common/Lua.cc
@@ -43,8 +43,12 @@ bool Lua::readVariable( InputStream* istream )
l_pushnil();
return true;
}
- case 'b': {
- l_pushbool( istream->readBool() );
+ case 'F': {
+ l_pushbool( false );
+ return true;
+ }
+ case 'T': {
+ l_pushbool( true );
return true;
}
case 'n': {
@@ -84,8 +88,7 @@ void Lua::writeVariable( BufferStream* ostream )
break;
}
case LUA_TBOOLEAN: {
- ostream->writeChar( 'b' );
- ostream->writeBool( l_tobool( -1 ) != 0 );
+ ostream->writeChar( l_tobool( -1 ) ? 'T' : 'F' );
break;
}
case LUA_TNUMBER: {
View
14 src/matrix/Bot.cc
@@ -40,6 +40,7 @@ const float Bot::AIR_FRICTION = 0.01f;
const float Bot::LADDER_SLIP_MOMENTUM = 16.0f;
const float Bot::WOUNDED_THRESHOLD = 0.70f;
+const float Bot::DROWNING_RATIO = 8.00f;
const float Bot::CORPSE_FADE_FACTOR = 0.50f / 100.0f;
const float Bot::INSTRUMENT_DIST = 2.00f;
@@ -500,12 +501,10 @@ void Bot::onUpdate()
stamina -= clazz->staminaWaterDrain;
if( stamina < 0.0f ) {
- float oldLife = life;
-
- life += stamina;
+ life += stamina * DROWNING_RATIO;
stamina = 0.0f;
- if( int( life ) / 8 != int( oldLife ) / 8 ) {
+ if( ( uint( index ) + uint( timer.ticks ) ) % Timer::TICKS_PER_SEC == 0 ) {
addEvent( EVENT_DAMAGE, 1.0f );
}
}
@@ -776,7 +775,7 @@ void Bot::onUpdate()
p.z = originalZ;
}
}
-stepSucceeded:
+ stepSucceeded:
Vec3 desiredMomentum = move;
@@ -892,7 +891,8 @@ void Bot::onUpdate()
const Bot* cargoBot = static_cast<const Bot*>( cargoObj );
if( cargoObj == nullptr || cargoObj->cell == nullptr || ( cargoObj->flags & BELOW_BIT ) ||
- ( actions & ACTION_JUMP ) || ( ( cargoBot->flags & BOT_BIT ) &&
+ ( state & ( LADDER_BIT | LEDGE_BIT ) ) || ( actions & ACTION_JUMP ) ||
+ ( ( cargoObj->flags & BOT_BIT ) &&
( ( cargoBot->actions & ACTION_JUMP ) || ( cargoBot->cargo >= 0 ) ) ) )
{
releaseCargo();
@@ -1121,7 +1121,7 @@ void Bot::onUpdate()
item->momentum = velocity;
if( ( actions & ~oldActions & ACTION_INV_GRAB ) &&
- !( state & ( LADDER_BIT | LEDGE_BIT | SWIMMING_BIT ) ) && weapon < 0 )
+ !( state & ( LADDER_BIT | LEDGE_BIT ) ) && weapon < 0 )
{
grabCargo( item );
View
1  src/matrix/Bot.hh
@@ -139,6 +139,7 @@ class Bot : public Dynamic
static const float LADDER_SLIP_MOMENTUM;
static const float WOUNDED_THRESHOLD;
+ static const float DROWNING_RATIO;
static const float CORPSE_FADE_FACTOR;
static const float INSTRUMENT_DIST;
View
4 src/ozCore/Alloc.cc
@@ -124,7 +124,6 @@ static void eraseTraceEntry( AllocMode mode, void* ptr )
}
st = st->next;
}
-
if( st == nullptr ) {
OZ_ERROR( mode == OBJECT ? "ALLOC: Freeing object at %p that has not been allocated" :
"ALLOC: Freeing array at %p that has not been allocated", ptr );
@@ -133,8 +132,7 @@ static void eraseTraceEntry( AllocMode mode, void* ptr )
OZ_ERROR( mode == OBJECT ? "ALLOC: new[] -> delete mismatch for block at %p" :
"ALLOC: new -> delete[] mismatch for block at %p", ptr );
}
-
-backtraceFound:
+ backtraceFound:
free( st );
}
View
4 src/ozCore/Array.hh
@@ -48,12 +48,12 @@ class Array
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ArrayIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ArrayIterator<Elem> Iterator;
View
33 src/ozCore/Buffer.cc
@@ -33,6 +33,18 @@ Buffer::Buffer( int size_ ) :
data( size_ == 0 ? nullptr : new char[size_] ), size( size_ )
{}
+Buffer::Buffer( const char* data_, int size_ ) :
+ data( size_ == 0 ? nullptr : new char[size_] ), size( size_ )
+{
+ mCopy( data, data_, size_t( size ) );
+}
+
+Buffer::Buffer( const String& s ) :
+ data( s.length() == 0 ? nullptr : new char[s.length()] ), size( s.length() )
+{
+ mCopy( data, s.cstr(), size_t( size ) );
+}
+
Buffer::~Buffer()
{
deallocate();
@@ -86,6 +98,27 @@ Buffer& Buffer::operator = ( Buffer&& b )
return *this;
}
+String Buffer::toString() const
+{
+ char* buffer;
+ String s = String::create( size, &buffer );
+
+ mCopy( buffer, data, size_t( size ) );
+ return s;
+}
+
+void Buffer::resize( int newSize )
+{
+ hard_assert( newSize >= 0 );
+
+ char* newData = newSize == 0 ? nullptr : new char[newSize];
+ mCopy( newData, data, size_t( min( newSize, size ) ) );
+ delete[] data;
+
+ data = newData;
+ size = newSize;
+}
+
void Buffer::allocate( int size_ )
{
hard_assert( size == 0 && size_ > 0 );
View
22 src/ozCore/Buffer.hh
@@ -48,11 +48,21 @@ class Buffer
public:
/**
- * Create a buffer of size `size`.
+ * Create an uninitialised buffer of size `size`.
*/
explicit Buffer( int size = 0 );
/**
+ * Create a buffer of size `size` and copy `data` into it.
+ */
+ explicit Buffer( const char* data, int size );
+
+ /**
+ * Create a buffer containing the given string (without the terminating null character).
+ */
+ explicit Buffer( const String& s );
+
+ /**
* Destructor.
*/
~Buffer();
@@ -156,6 +166,16 @@ class Buffer
}
/**
+ * Create a string from the buffer contents. Terminating null byte is always appended.
+ */
+ String toString() const;
+
+ /**
+ * Resize the buffer.
+ */
+ void resize( int newSize );
+
+ /**
* For an empty buffer, allocate new storage of `size` bytes.
*/
void allocate( int size );
View
4 src/ozCore/Chain.hh
@@ -117,12 +117,12 @@ class Chain
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ChainIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ChainIterator<Elem> Iterator;
View
4 src/ozCore/DArray.hh
@@ -47,12 +47,12 @@ class DArray
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ArrayIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ArrayIterator<Elem> Iterator;
View
4 src/ozCore/DChain.hh
@@ -119,12 +119,12 @@ class DChain
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ChainIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ChainIterator<Elem> Iterator;
View
115 src/ozCore/File.cc
@@ -597,42 +597,36 @@ InputStream File::inputStream( Endian::Order order ) const
return InputStream( data, data + fileSize, order );
}
-Buffer File::read() const
+bool File::read( char* buffer, int* size ) const
{
- Buffer buffer;
+ if( fileSize <= 0 ) {
+ *size = 0;
+ return fileSize == 0;
+ }
if( fileFS == VIRTUAL ) {
PHYSFS_File* file = PHYSFS_openRead( filePath );
if( file == nullptr ) {
- return buffer;
+ *size = 0;
+ return false;
}
- int size = int( PHYSFS_fileLength( file ) );
- buffer.allocate( size );
-
- int result = int( PHYSFS_readBytes( file, buffer.begin(), ulong64( size ) ) );
+ int result = int( PHYSFS_readBytes( file, buffer, ulong64( *size ) ) );
PHYSFS_close( file );
- if( result != size ) {
- buffer.deallocate();
- }
+ *size = result;
}
else {
if( data != nullptr ) {
- buffer.allocate( fileSize );
- mCopy( buffer.begin(), data, size_t( fileSize ) );
- return buffer;
- }
- if( fileSize < 0 ) {
- return buffer;
+ *size = min( *size, fileSize );
+ mCopy( buffer, data, size_t( *size ) );
+ return true;
}
#if defined( __native_client__ )
- buffer.allocate( fileSize );
-
- descriptor->buffer = buffer.begin();
- descriptor->size = fileSize;
+ descriptor->buffer = buffer;
+ descriptor->size = min( *size, fileSize );
descriptor->offset = 0;
DEFINE_CALLBACK( read, {
@@ -678,65 +672,81 @@ Buffer File::read() const
MAIN_CALL( open );
SEMAPHORE_WAIT();
- if( descriptor->offset < fileSize ) {
- buffer.deallocate();
- return buffer;
+ if( descriptor->offset != descriptor->size ) {
+ *size = 0;
+ return false;
}
+ *size = descriptor->offset;
+
#elif defined( _WIN32 )
HANDLE file = CreateFile( filePath, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, nullptr );
if( file == nullptr ) {
- return buffer;
- }
-
- int size = int( GetFileSize( file, nullptr ) );
- if( size <= 0 || size == int( INVALID_FILE_SIZE ) ) {
- return buffer;
+ *size = 0;
+ return false;
}
- buffer.allocate( size );
-
DWORD read;
- BOOL result = ReadFile( file, buffer.begin(), DWORD( size ), &read, nullptr );
+ BOOL result = ReadFile( file, buffer, DWORD( size ), &read, nullptr );
CloseHandle( file );
- if( result == 0 || int( read ) != size ) {
- buffer.deallocate();
- return buffer;
+ if( result == 0 ) {
+ *size = 0;
+ return false;
}
+ *size = int( read );
+
#else
int fd = open( filePath, O_RDONLY );
if( fd < 0 ) {
- return buffer;
+ *size = 0;
+ return false;
}
- struct stat statInfo;
- if( fstat( fd, &statInfo ) != 0 ) {
- close( fd );
- return buffer;
- }
+ int result = int( ::read( fd, buffer, size_t( *size ) ) );
+ close( fd );
- int size = int( statInfo.st_size );
- buffer.allocate( size );
+ *size = result;
+#endif
+ }
- int result = int( ::read( fd, buffer.begin(), size_t( size ) ) );
- close( fd );
+ return true;
+}
- if( result != size ) {
- buffer.deallocate();
- return buffer;
- }
+Buffer File::read() const
+{
+ Buffer buffer;
-#endif
+ if( fileSize <= 0 ) {
+ return buffer;
}
+ int size = fileSize;
+ buffer.allocate( size );
+
+ read( buffer.begin(), &size );
+
+ if( size != fileSize ) {
+ buffer.resize( size );
+ }
return buffer;
}
+String File::readString() const
+{
+ char* buffer;
+ int size = fileSize;
+ String s = String::create( size, &buffer );
+
+ read( buffer, &size );
+ buffer[size] = '\0';
+ return s;
+}
+
bool File::write( const char* buffer, int size ) const
{
if( fileFS == VIRTUAL ) {
@@ -852,6 +862,11 @@ bool File::write( const Buffer& buffer ) const
return write( buffer.begin(), buffer.length() );
}
+bool File::writeString( const String& s ) const
+{
+ return write( s.cstr(), s.length() );
+}
+
DArray<File> File::ls() const
{
DArray<File> array;
View
26 src/ozCore/File.hh
@@ -126,7 +126,7 @@ class File
/**
* Access file to update its type, size and modification time.
*
- * @return true iff call succeeds, i.e. file exists.
+ * @return true iff file exists.
*/
bool stat();
@@ -239,14 +239,26 @@ class File
InputStream inputStream( Endian::Order order = Endian::NATIVE ) const;
/**
+ * Read at most `size` bytes from file and update `size` to the number of bytes read.
+ */
+ bool read( char* buffer, int* size ) const;
+
+ /**
* Read file into a buffer.
*/
Buffer read() const;
/**
+ * Read file as a string.
+ *
+ * Terminating null character is always assured.
+ */
+ String readString() const;
+
+ /**
* Write buffer contents to the file.
*
- * It also sets file type on `REGULAR` and updates file size if it succeeds.
+ * @note
* Write operation is not possible while file is mapped.
*/
bool write( const char* data, int size ) const;
@@ -254,12 +266,20 @@ class File
/**
* Write buffer contents into a file.
*
- * It also sets file type on `REGULAR` and updates file size if it succeeds.
+ * @note
* Write operation is not possible while file is mapped.
*/
bool write( const Buffer& buffer ) const;
/**
+ * Write string into a file (omitting the terminating null character).
+ *
+ * @note
+ * Write operation is not possible while file is mapped.
+ */
+ bool writeString( const String& s ) const;
+
+ /**
* Generate a list of files in directory.
*
* Hidden files (in Unix means, so everything starting with '.') are skipped.
View
4 src/ozCore/HashMap.hh
@@ -145,12 +145,12 @@ class HashMap
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef HashIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef HashIterator<Elem> Iterator;
View
4 src/ozCore/HashSet.hh
@@ -143,12 +143,12 @@ class HashSet
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef HashIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef HashIterator<Elem> Iterator;
View
158 src/ozCore/JSON.cc
@@ -105,26 +105,26 @@ struct JSON::ObjectData : JSON::Data
HashMap<String, JSON> table;
};
-JSON::CIterator::CIterator( const ObjectData* data ) :
+JSON::ObjectCIterator::ObjectCIterator( const ObjectData* data ) :
IteratorBase<const HashMap<String, JSON>::Elem>( nullptr ), objectIter( data->table.citer() )
{
elem = objectIter;
}
-JSON::CIterator& JSON::CIterator::operator ++ ()
+JSON::ObjectCIterator& JSON::ObjectCIterator::operator ++ ()
{
++objectIter;
elem = objectIter;
return *this;
}
-JSON::Iterator::Iterator( ObjectData* data ) :
+JSON::ObjectIterator::ObjectIterator( ObjectData* data ) :
IteratorBase<HashMap<String, JSON>::Elem>( nullptr ), objectIter( data->table.iter() )
{
elem = objectIter;
}
-JSON::Iterator& JSON::Iterator::operator ++ ()
+JSON::ObjectIterator& JSON::ObjectIterator::operator ++ ()
{
++objectIter;
elem = objectIter;
@@ -133,6 +133,13 @@ JSON::Iterator& JSON::Iterator::operator ++ ()
struct JSON::Parser
{
+ enum BlanksMode
+ {
+ WHITESPACE,
+ LINE_COMMENT,
+ MULTILINE_COMMENT
+ };
+
struct Position
{
InputStream* istream;
@@ -188,6 +195,8 @@ char JSON::Parser::Position::readChar()
OZ_HIDDEN
void JSON::Parser::Position::backChar()
{
+ hard_assert( line != oldLine || column != oldColumn );
+
istream->seek( istream->pos() - 1 );
line = oldLine;
@@ -241,13 +250,61 @@ JSON::Parser::Parser( InputStream* istream, const char* path ) :
OZ_HIDDEN
char JSON::Parser::skipBlanks()
{
- char ch;
- do {
- ch = pos.readChar();
+ BlanksMode mode = WHITESPACE;
+ char ch1 = ' ', ch2 = ' ';
+
+ switch( mode ) {
+ case WHITESPACE: {
+ skipWhitespace:
+ do {
+ ch1 = ch2;
+ ch2 = pos.readChar();
+ }
+ while( String::isBlank( ch2 ) );
+
+ if( ch2 == '/' ) {
+ ch1 = ch2;
+ ch2 = pos.readChar();
+
+ if( ch2 == '/' ) {
+ goto skipLineComment;
+ }
+ else if( ch2 == '*' ) {
+ ch2 = pos.readChar();
+ goto skipMultilineComment;
+ }
+ else {
+ ch2 = ch1;
+ pos.backChar();
+ }
+ }
+ break;
+ }
+ case LINE_COMMENT: {
+ skipLineComment:
+ do {
+ ch1 = ch2;
+ ch2 = pos.readChar();
+ }
+ while( ch2 != '\n' );
+
+ mode = WHITESPACE;
+ goto skipWhitespace;
+ }
+ case MULTILINE_COMMENT: {
+ skipMultilineComment:
+ do {
+ ch1 = ch2;
+ ch2 = pos.readChar();
+ }
+ while( ch1 != '*' || ch2 != '/' );
+
+ mode = WHITESPACE;
+ goto skipWhitespace;
+ }
}
- while( String::isBlank( ch ) );
- return ch;
+ return ch2;
}
OZ_HIDDEN
@@ -430,11 +487,6 @@ JSON JSON::Parser::parseObject()
}
JSON value = parseValue();
-
- if( key.beginsWith( "//" ) ) {
- setAccessed( &value );
- }
-
table.add( static_cast<String&&>( key ), static_cast<JSON&&>( value ) );
ch = skipBlanks();
@@ -759,26 +811,52 @@ int JSON::isEmpty() const
}
}
-bool JSON::contains( const char* key )
+JSON::ArrayCIterator JSON::arrayCIter() const
{
- wasAccessed = true;
+ if( valueType == ARRAY ) {
+ const ArrayData* arrayData = static_cast<const ArrayData*>( data );
- if( valueType == NIL ) {
- return false;
+ return ArrayCIterator( arrayData->list.begin(), arrayData->list.end() );
}
- else if( valueType != OBJECT ) {
- OZ_ERROR( "JSON value accessed as an object: %s", toString().cstr() );
+ else {
+ return ArrayCIterator();
}
+}
- const HashMap<String, JSON>& table = static_cast<const ObjectData*>( data )->table;
- const JSON* value = table.find( key );
+JSON::ArrayIterator JSON::arrayIter()
+{
+ if( valueType == ARRAY ) {
+ ArrayData* arrayData = static_cast<ArrayData*>( data );
- if( value == nullptr ) {
- return false;
+ return ArrayIterator( arrayData->list.begin(), arrayData->list.end() );
+ }
+ else {
+ return ArrayIterator();
}
+}
- value->wasAccessed = true;
- return true;
+JSON::ObjectCIterator JSON::objectCIter() const
+{
+ if( valueType == OBJECT ) {
+ const ObjectData* objectData = static_cast<const ObjectData*>( data );
+
+ return ObjectCIterator( objectData );
+ }
+ else {
+ return ObjectCIterator();
+ }
+}
+
+JSON::ObjectIterator JSON::objectIter()
+{
+ if( valueType == OBJECT ) {
+ ObjectData* objectData = static_cast<ObjectData*>( data );
+
+ return ObjectIterator( objectData );
+ }
+ else {
+ return ObjectIterator();
+ }
}
const JSON& JSON::operator [] ( int i ) const
@@ -824,28 +902,26 @@ const JSON& JSON::operator [] ( const char* key ) const
return *value;
}
-JSON::CIterator JSON::objectCIter() const
+bool JSON::contains( const char* key )
{
- if( valueType == OBJECT ) {
- const ObjectData* objectData = static_cast<const ObjectData*>( data );
+ wasAccessed = true;
- return CIterator( objectData );
+ if( valueType == NIL ) {
+ return false;
}
- else {
- return CIterator();
+ else if( valueType != OBJECT ) {
+ OZ_ERROR( "JSON value accessed as an object: %s", toString().cstr() );
}
-}
-JSON::Iterator JSON::objectIter()
-{
- if( valueType == OBJECT ) {
- ObjectData* objectData = static_cast<ObjectData*>( data );
+ const HashMap<String, JSON>& table = static_cast<const ObjectData*>( data )->table;
+ const JSON* value = table.find( key );
- return Iterator( objectData );
- }
- else {
- return Iterator();
+ if( value == nullptr ) {
+ return false;
}
+
+ value->wasAccessed = true;
+ return true;
}
bool JSON::asBool() const
View
73 src/ozCore/JSON.hh
@@ -40,7 +40,8 @@ namespace oz
*
* This implementation strictly follows JSON standard with the following exceptions:
* @li `inf` and `-inf` (case-sensitive) represent positive and negative infinity respectively,
- * @li `nan` and `-nan` (case-sensitive) represent not-a-number.
+ * @li `nan` and `-nan` (case-sensitive) represent not-a-number and
+ * @li C++-style comments are allowed.
*/
class JSON
{
@@ -73,9 +74,19 @@ class JSON
public:
/**
- * %Iterator for %JSON objects with constant access.
+ * %Iterator for %JSON arrays with constant access to elements.
*/
- class CIterator : public IteratorBase<const HashMap<String, JSON>::Elem>
+ typedef oz::ArrayIterator<const JSON> ArrayCIterator;
+
+ /**
+ * %Iterator for %JSON arrays with non-constant access to elements.
+ */
+ typedef oz::ArrayIterator<JSON> ArrayIterator;
+
+ /**
+ * %Iterator for %JSON objects with constant access to elements.
+ */
+ class ObjectCIterator : public IteratorBase<const HashMap<String, JSON>::Elem>
{
private:
@@ -90,26 +101,26 @@ class JSON
* Default constructor, creates an invalid iterator.
*/
OZ_ALWAYS_INLINE
- explicit CIterator() :
+ explicit ObjectCIterator() :
IteratorBase<const HashMap<String, JSON>::Elem>( nullptr )
{}
/**
* Create iterator for the given %JSON object's data.
*/
- explicit CIterator( const ObjectData* data );
+ explicit ObjectCIterator( const ObjectData* data );
/**
* Advance to the next element.
*/
- CIterator& operator ++ ();
+ ObjectCIterator& operator ++ ();
};
/**
- * %Iterator for %JSON objects with non-constant access.
+ * %Iterator for %JSON objects with non-constant access to elements.
*/
- class Iterator : public IteratorBase<HashMap<String, JSON>::Elem>
+ class ObjectIterator : public IteratorBase<HashMap<String, JSON>::Elem>
{
private:
@@ -124,19 +135,19 @@ class JSON
* Default constructor, creates an invalid iterator.
*/
OZ_ALWAYS_INLINE
- explicit Iterator() :
+ explicit ObjectIterator() :
IteratorBase<HashMap<String, JSON>::Elem>( nullptr )
{}
/**
* Create iterator for the given %JSON object's data.
*/
- explicit Iterator( ObjectData* data );
+ explicit ObjectIterator( ObjectData* data );
/**
* Advance to the next element.
*/
- Iterator& operator ++ ();
+ ObjectIterator& operator ++ ();
};
@@ -208,11 +219,32 @@ class JSON
int isEmpty() const;
/**
- * True iff value is an object and contains the given key.
+ * %JSON array iterator with constant access.
*
- * If value is not either null or an object, `System::error()` is invoked.
+ * An invalid iterator is returned if the %JSON element is not an array.
*/
- bool contains( const char* key );
+ ArrayCIterator arrayCIter() const;
+
+ /**
+ * %JSON array iterator with non-constant access.
+ *
+ * An invalid iterator is returned if the %JSON element is not an array.
+ */
+ ArrayIterator arrayIter();
+
+ /**
+ * %JSON object iterator with constant access.
+ *
+ * An invalid iterator is returned if the %JSON element is not an object.
+ */
+ ObjectCIterator objectCIter() const;
+
+ /**
+ * %JSON object iterator with non-constant access.
+ *
+ * An invalid iterator is returned if the %JSON element is not an object.
+ */
+ ObjectIterator objectIter();
/**
* Returns value at position `i` in an array.
@@ -231,18 +263,11 @@ class JSON
const JSON& operator [] ( const char* key ) const;
/**
- * %JSON object iterator with constant access.
- *
- * An invalid iterator is returned if the %JSON element is not an object.
- */
- CIterator objectCIter() const;
-
- /**
- * %JSON object iterator with non-constant access.
+ * True iff value is an object and contains the given key.
*
- * An invalid iterator is returned if the %JSON element is not an object.
+ * If value is not either null or an object, `System::error()` is invoked.
*/
- Iterator objectIter();
+ bool contains( const char* key );
/**
* Get boolean value.
View
4 src/ozCore/List.hh
@@ -55,12 +55,12 @@ class List
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ArrayIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ArrayIterator<Elem> Iterator;
View
4 src/ozCore/Map.hh
@@ -81,12 +81,12 @@ class Map
};
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ArrayIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ArrayIterator<Elem> Iterator;
View
4 src/ozCore/SList.hh
@@ -50,12 +50,12 @@ class SList
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ArrayIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ArrayIterator<Elem> Iterator;
View
4 src/ozCore/Set.hh
@@ -58,12 +58,12 @@ class Set
public:
/**
- * %Iterator with constant access to container elements.
+ * %Iterator with constant access to elements.
*/
typedef ArrayIterator<const Elem> CIterator;
/**
- * %Iterator with non-constant access to container elements.
+ * %Iterator with non-constant access to elements.
*/
typedef ArrayIterator<Elem> Iterator;
View
2  src/ozCore/String.cc
@@ -320,7 +320,7 @@ float String::parseFloat( const char* s, const char** end )
}
// Invalid.
else {
-invalidNumber:
+ invalidNumber:
if( end != nullptr ) {
*end = s;
}
View
8 src/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-if( PLATFORM_EMBEDDED )
+if( NOT OZ_TESTS )
return()
endif()
@@ -15,5 +15,9 @@ target_link_libraries( quicksort ozCore )
add_executable( simd simd.cc )
target_link_libraries( simd ozCore )
+pkg_check_modules( COLLADA collada-dom )
+
+include_directories( SYSTEM /usr/include/collada-dom2.4 )
+include_directories( SYSTEM /usr/include/collada-dom2.4/1.4 )
add_executable( test test.cc )
-target_link_libraries( test ozCore )
+target_link_libraries( test ozCore ${COLLADA_LIBRARIES} boost_system )
View
24 src/tests/test.cc
@@ -27,6 +27,9 @@
#include <clocale>
#include <climits>
+#include <dae.h>
+#include <1.4/dom/domCOLLADA.h>
+
using namespace oz;
void bar();
@@ -115,11 +118,28 @@ class Foo
};
+using namespace ColladaDOM141;
+
int main()
{
System::init();
- JSON json( File( File::NATIVE, "/home/davorin/.config/chromium/Default/Bookmarks" ) );
- Log() << json.toFormattedString();
+ File file( File::NATIVE, "/home/davorin/untitled.dae" );
+
+ DAE dae;
+ domElement* root = dae.open( file.path().cstr() );
+ hard_assert( root != nullptr );
+ domCOLLADA* dom = static_cast<domCOLLADA*>( dae.getDom( file.name() ) );
+ hard_assert( dom != nullptr );
+
+ auto geometries = dom->getLibrary_geometries_array();
+ for( size_t i = 0; i < geometries.getCount(); ++i ) {
+ Log() << "Geometry #" << i << ": " << geometries[i]->getName() << "\n";
+
+ auto meshes = geometries[i]->getGeometry_array();
+ for( size_t j = 0; j < meshes.getCount(); ++j ) {
+ Log() << "+ Mesh #" << j << ": " << meshes[j]->getName() << "\n";
+ }
+ }
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.