1 #ifndef __RTFX_OBJECT__
2 #define __RTFX_OBJECT__
22 #include "RTFXRecorder.h"
23 #include "RTFXHelpers.h"
24 #include "RTFXPropertyIncludes.h"
63 RTFXObject() : hasChanged( true ), shouldBeDeleted( false ), shouldBeResent( false ), isPartial( false )
66 id = boost::uuids::nil_uuid();
67 owner = boost::uuids::nil_uuid();
76 nameProperty->
SetAll(
"name",
"name of property",
true, GetANewPropertyID() );
77 nameProperty->
SetDataType( RTFXProperty::DATASTRING );
81 propertyMap[ nameProperty->
GetID() ] = nameProperty;
82 propertyNameLookup[ nameProperty->
GetName() ] = nameProperty->
GetID();
90 debug( ostringstream().flush() <<
"RTFXObject::Destructor: " << name << endl );
92 DeleteAllProperties();
101 debug( ostringstream().flush() <<
"RTFXObject::Copy Constructor: copying data - " << _o.
name << endl );
115 CopyProperties( &_o );
136 boost::uuids::uuid GetID()
143 void SetID( boost::uuids::uuid _id )
152 boost::uuids::uuid GetOwner()
159 void SetOwner( boost::uuids::uuid _owner )
173 void SetChanged(
bool _changed )
176 hasChanged = _changed;
183 void SetDeleteMe(
bool _deleteme ) { shouldBeDeleted = _deleteme; }
189 void SetResend(
bool _resend ) { shouldBeResent = _resend; }
199 void SetPartial(
bool _partial )
202 isPartial = _partial;
206 std::string GetName()
215 void SetName( std::string _name )
224 std::string GetDescription()
231 void SetDescription( std::string _description )
234 description = _description;
243 if ( PropertyExists( _property->
GetName() ) )
246 if ( _property->
GetID() == 0 && nextPropertyID != 0 )
248 _property->
SetID( nextPropertyID );
252 propertyMap[ _property->
GetID() ] = _property;
253 propertyNameLookup[ _property->
GetName() ] = _property->
GetID();
258 bool PropertyExists(
unsigned int _id )
261 if ( propertyMap.find( _id ) == propertyMap.end() )
268 bool PropertyExists( std::string _propertyName )
271 if ( propertyNameLookup.find( _propertyName ) == propertyNameLookup.end() )
277 unsigned int GetANewPropertyID()
280 unsigned int returnValue_ = nextPropertyID;
292 unsigned int propertyID_ = propertyNameLookup[ _propertyName ];
293 return propertyMap[ propertyID_ ];
301 return propertyMap[ _id ];
305 void DeleteProperty(
unsigned int _id )
310 propertyMap.erase( _id );
311 propertyNameLookup.erase( ptr_->
GetName() );
319 void DeletePropertyByName( std::string _propertyName )
324 propertyMap.erase( ptr_->
GetID() );
325 propertyNameLookup.erase( _propertyName );
344 if ( name.compare( _object->
name ) != 0 )
347 if ( description.compare( _object->
description ) != 0 )
353 if ( isInstance && ( instanceOfID != _object->
instanceOfID ) )
357 if ( propertyMap.size() != _object->
propertyMap.size() )
361 std::map<std::string, unsigned int>::iterator iter_ = propertyNameLookup.begin();
362 while ( iter_ != propertyNameLookup.end() )
367 if ( ptr1_ == NULL || ptr2_ == NULL )
370 equal_ &= ptr1_->
EqualTo( ptr2_ );
377 virtual void ToNative( AXISFRAME _frame ) = 0;
380 virtual void FromNative( AXISFRAME _frame ) = 0;
383 virtual void ChangeFrame( AXISFRAME _from, AXISFRAME _to ) = 0;
387 virtual std::vector<RTFXProperty *> GetChangedProperties()
390 std::vector<RTFXProperty *> changedProperties_;
392 std::map<unsigned int, RTFXProperty *>::iterator iter_ = propertyMap.begin();
394 while ( iter_ != propertyMap.end() )
399 changedProperties_.push_back( ptr_ );
404 return changedProperties_;
408 virtual void SetAllPropertyChanged(
bool _value )
411 std::map<unsigned int, RTFXProperty *>::iterator iter_ = propertyMap.begin();
413 while ( iter_ != propertyMap.end() )
415 verbose( ostringstream().flush() <<
"RTFXObject::SetAllPropertyChanged: property - " << (*iter_).first << endl );
424 virtual bool ExistChangedProperties()
427 std::map<unsigned int, RTFXProperty *>::iterator iter_ = propertyMap.begin();
428 while ( iter_ != propertyMap.end() )
438 void DeleteAllProperties()
441 map<unsigned int, RTFXProperty *>::iterator iter_ = propertyMap.begin();
442 while ( iter_ != propertyMap.end() )
447 DeleteProperty( ptr_->
GetID() );
452 map<unsigned int, RTFXProperty *> tmp_;
453 tmp_.swap( propertyMap );
455 map<string, unsigned int> tmp2_;
456 tmp2_.swap( propertyNameLookup );
461 void SetFrame( AXISFRAME _frame ) { frame = _frame; }
469 std::map<unsigned int, RTFXProperty *>::const_iterator iter_ = _obj->
propertyMap.begin();
476 if ( PropertyExists( ptr_->
GetName() ) )
477 localProperty_ = GetProperty( ptr_->
GetName() );
479 if ( localProperty_ != NULL )
480 localProperty_->
Copy( ptr_ );
490 case RTFXProperty::BASICARRAY:
492 if ( dataType_ == RTFXProperty::CHAR )
494 else if ( dataType_ == RTFXProperty::BOOL )
496 else if ( dataType_ == RTFXProperty::DOUBLE || dataType_ == RTFXProperty::UNKNOWN )
498 else if ( dataType_ == RTFXProperty::FLOAT )
500 else if ( dataType_ == RTFXProperty::INT )
502 else if ( dataType_ == RTFXProperty::UNSIGNEDINT )
506 case RTFXProperty::BASICTYPE:
508 if ( dataType_ == RTFXProperty::CHAR )
510 else if ( dataType_ == RTFXProperty::BOOL )
512 else if ( dataType_ == RTFXProperty::DOUBLE || dataType_ == RTFXProperty::UNKNOWN )
514 else if ( dataType_ == RTFXProperty::FLOAT )
516 else if ( dataType_ == RTFXProperty::INT )
518 else if ( dataType_ == RTFXProperty::UNSIGNEDINT )
522 case RTFXProperty::CHARARRAY:
527 case RTFXProperty::COLOUR:
532 case RTFXProperty::MATRIX4:
537 case RTFXProperty::POINT3:
542 case RTFXProperty::RAWDATA:
547 case RTFXProperty::STRING:
552 case RTFXProperty::VECTOR3:
557 case RTFXProperty::VECTOROF:
559 if ( dataType_ == RTFXProperty::CHAR )
561 else if ( dataType_ == RTFXProperty::BOOL )
563 else if ( dataType_ == RTFXProperty::DATASTRING )
565 else if ( dataType_ == RTFXProperty::DOUBLE || dataType_ == RTFXProperty::UNKNOWN )
567 else if ( dataType_ == RTFXProperty::FLOAT )
569 else if ( dataType_ == RTFXProperty::INT )
571 else if ( dataType_ == RTFXProperty::UNSIGNEDINT )
575 case RTFXProperty::DELETEOBJECT:
586 if ( newPtr_ != NULL )
588 newPtr_->
Copy( ptr_ );
589 AddProperty( newPtr_ );
604 void SetInstanceOfID( boost::uuids::uuid _instanceOfID ) { instanceOfID = _instanceOfID; }
610 void SetNew(
bool _isnew ) { isNew = _isnew; }
616 void RemovePropertyReference(
string _name )
619 ptr_ = GetProperty( _name );
620 if ( ptr_ == NULL )
return;
623 propertyMap.erase( ptr_->
GetID() );
624 propertyNameLookup.erase( _name );
655 boost::uuids::uuid
id;
702 friend class boost::serialization::access;
704 template<
class Archive>
705 void serialize( Archive &_ar,
const unsigned int _version )
708 _ar & type &
id & owner & hasChanged & shouldBeDeleted & shouldBeResent & isPartial & isInstance & instanceOfID & name & description;
710 _ar & nextPropertyID & propertyMap & propertyNameLookup;