From Wang Rui, "I'd like to submit the changes that will put ObjectProperty and ObjectMark variables into the InputStream/OutputStream class instead of static ones. This should avoid the threading problem and won't repeatedly reallocate memory for the properties. Some of the wrappers will be slightly modified to use the property variable stored in the InputStream/OutputStream as well."
This commit is contained in:
@@ -88,13 +88,15 @@ struct ObjectGLenum
|
||||
class ObjectProperty
|
||||
{
|
||||
public:
|
||||
ObjectProperty() : _value(0), _mapProperty(false) {}
|
||||
|
||||
ObjectProperty( const char* name, int value=0, bool useMap=false )
|
||||
: _name(name), _value(value), _mapProperty(useMap) {}
|
||||
|
||||
ObjectProperty( const ObjectProperty& copy )
|
||||
: _name(copy._name), _value(copy._value), _mapProperty(copy._mapProperty) {}
|
||||
|
||||
ObjectProperty& proto( const char* name )
|
||||
ObjectProperty& operator()( const char* name )
|
||||
{ _name = name; return *this; }
|
||||
|
||||
void set( int v ) { _value = v; }
|
||||
@@ -103,34 +105,24 @@ public:
|
||||
std::string _name;
|
||||
int _value;
|
||||
bool _mapProperty;
|
||||
|
||||
protected:
|
||||
ObjectProperty():_value(0),_mapProperty(false) {}
|
||||
};
|
||||
static ObjectProperty defaultProp("");
|
||||
|
||||
#define PROPERTY(name) defaultProp.proto(name)
|
||||
#define MAPPEE(pairName, value) osgDB::ObjectProperty(#pairName, value, true)
|
||||
#define DEF_PROPERTY(name, var) osgDB::ObjectProperty var(name);
|
||||
#define DEF_MAPPEE(pairName, var) osgDB::ObjectProperty var(#pairName, 0, true);
|
||||
|
||||
class ObjectMark
|
||||
{
|
||||
public:
|
||||
ObjectMark( const char* name, int delta=0 )
|
||||
: _name(name), _indentDelta(delta) {}
|
||||
ObjectMark() : _indentDelta(0) {}
|
||||
|
||||
ObjectMark( const ObjectMark& copy )
|
||||
: _name(copy._name), _indentDelta(copy._indentDelta) {}
|
||||
|
||||
void set( const char* name, int delta=0 )
|
||||
{ _name = name, _indentDelta = delta; }
|
||||
|
||||
std::string _name;
|
||||
int _indentDelta;
|
||||
|
||||
protected:
|
||||
ObjectMark():_indentDelta(0) {}
|
||||
};
|
||||
static ObjectMark BEGIN_BRACKET("{", +INDENT_VALUE);
|
||||
static ObjectMark END_BRACKET ("}", -INDENT_VALUE);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -157,6 +157,11 @@ public:
|
||||
inline void throwException( const std::string& msg );
|
||||
const InputException* getException() const { return _exception.get(); }
|
||||
|
||||
// Property & mask variables
|
||||
ObjectProperty PROPERTY;
|
||||
ObjectMark BEGIN_BRACKET;
|
||||
ObjectMark END_BRACKET;
|
||||
|
||||
protected:
|
||||
inline void checkStream();
|
||||
void setWrapperSchema( const std::string& name, const std::string& properties );
|
||||
|
||||
@@ -164,6 +164,11 @@ public:
|
||||
inline void throwException( const std::string& msg );
|
||||
const OutputException* getException() const { return _exception.get(); }
|
||||
|
||||
// Property & mask variables
|
||||
ObjectProperty PROPERTY;
|
||||
ObjectMark BEGIN_BRACKET;
|
||||
ObjectMark END_BRACKET;
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
void writeArrayImplementation( const T*, int write_size, unsigned int numInRow=1 );
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
else
|
||||
{
|
||||
if ( !ok ) return true;
|
||||
os << PROPERTY(_name.c_str());
|
||||
os << os.PROPERTY(_name.c_str());
|
||||
}
|
||||
return (*_writer)(os, object);
|
||||
}
|
||||
@@ -251,7 +251,7 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str());
|
||||
os << os.PROPERTY((ParentType::_name).c_str());
|
||||
if ( _useHex ) os << std::hex;
|
||||
os << value;
|
||||
if ( _useHex ) os << std::dec;
|
||||
@@ -308,7 +308,7 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str()) << value << std::endl;
|
||||
os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -358,7 +358,7 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str()) << value << std::endl;
|
||||
os << os.PROPERTY((ParentType::_name).c_str()) << value << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -425,7 +425,7 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << std::endl;
|
||||
os << os.PROPERTY((ParentType::_name).c_str()) << GLENUM(value) << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -475,7 +475,7 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str());
|
||||
os << os.PROPERTY((ParentType::_name).c_str());
|
||||
os.writeWrappedString( value );
|
||||
os << std::endl;
|
||||
}
|
||||
@@ -517,11 +517,11 @@ public:
|
||||
is >> hasObject;
|
||||
if ( hasObject )
|
||||
{
|
||||
is >> BEGIN_BRACKET;
|
||||
is >> is.BEGIN_BRACKET;
|
||||
P* value = dynamic_cast<P*>( is.readObject() );
|
||||
if ( ParentType::_defaultValue!=value )
|
||||
(object.*_setter)( value );
|
||||
is >> END_BRACKET;
|
||||
is >> is.END_BRACKET;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -539,12 +539,12 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str()) << hasObject;
|
||||
os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
|
||||
if ( hasObject )
|
||||
{
|
||||
os << BEGIN_BRACKET << std::endl;
|
||||
os << os.BEGIN_BRACKET << std::endl;
|
||||
os.writeObject( value );
|
||||
os << END_BRACKET;
|
||||
os << os.END_BRACKET;
|
||||
}
|
||||
os << std::endl;
|
||||
}
|
||||
@@ -586,11 +586,11 @@ public:
|
||||
is >> hasObject;
|
||||
if ( hasObject )
|
||||
{
|
||||
is >> BEGIN_BRACKET;
|
||||
is >> is.BEGIN_BRACKET;
|
||||
P* value = dynamic_cast<P*>( is.readImage() );
|
||||
if ( ParentType::_defaultValue!=value )
|
||||
(object.*_setter)( value );
|
||||
is >> END_BRACKET;
|
||||
is >> is.END_BRACKET;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -608,12 +608,12 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str()) << hasObject;
|
||||
os << os.PROPERTY((ParentType::_name).c_str()) << hasObject;
|
||||
if ( hasObject )
|
||||
{
|
||||
os << BEGIN_BRACKET << std::endl;
|
||||
os << os.BEGIN_BRACKET << std::endl;
|
||||
os.writeImage( value );
|
||||
os << END_BRACKET;
|
||||
os << os.END_BRACKET;
|
||||
}
|
||||
os << std::endl;
|
||||
}
|
||||
@@ -673,7 +673,7 @@ public:
|
||||
}
|
||||
else if ( ParentType::_defaultValue!=value )
|
||||
{
|
||||
os << PROPERTY((ParentType::_name).c_str()) << getString(value) << std::endl;
|
||||
os << os.PROPERTY((ParentType::_name).c_str()) << getString(value) << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -720,7 +720,7 @@ public:
|
||||
else if ( is.matchString(_name) )
|
||||
{
|
||||
is >> size;
|
||||
if ( size>0 ) is >> BEGIN_BRACKET;
|
||||
if ( size>0 ) is >> is.BEGIN_BRACKET;
|
||||
for ( unsigned int i=0; i<size; ++i )
|
||||
{
|
||||
ValueType value;
|
||||
@@ -729,7 +729,7 @@ public:
|
||||
}
|
||||
if ( size>0 )
|
||||
{
|
||||
is >> END_BRACKET;
|
||||
is >> is.END_BRACKET;
|
||||
(object.*_setter)( list );
|
||||
}
|
||||
}
|
||||
@@ -752,14 +752,14 @@ public:
|
||||
}
|
||||
else if ( size>0 )
|
||||
{
|
||||
os << PROPERTY((_name).c_str()) << size << BEGIN_BRACKET << std::endl;
|
||||
os << os.PROPERTY((_name).c_str()) << size << os.BEGIN_BRACKET << std::endl;
|
||||
for ( ConstIterator itr=list.begin();
|
||||
itr!=list.end(); ++itr )
|
||||
{
|
||||
os << (*itr);
|
||||
}
|
||||
os << std::endl;
|
||||
os << END_BRACKET << std::endl;
|
||||
os << os.END_BRACKET << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user