NLLIGO::IPrimitive Class Reference

#include <primitive.h>

Inheritance diagram for NLLIGO::IPrimitive:

NLMISC::IClassable NLLIGO::CPrimNode NLLIGO::CPrimPath NLLIGO::CPrimPoint NLLIGO::CPrimZone

Properties

bool addPropertyByName (const char *property_name, IProperty *result)
virtual IPrimitivecopy () const=0
uint getNumProperty () const
virtual uint getNumVector () const=0
virtual CPrimVectorgetPrimVector ()=0
virtual const CPrimVectorgetPrimVector () const=0
bool getProperty (uint index, std::string &property_name, IProperty *&result)
bool getProperty (uint index, std::string &property_name, const IProperty *&result) const
bool getPropertyByName (const char *property_name, NLMISC::CRGBA &result) const
bool getPropertyByName (const char *property_name, const std::vector< std::string > *&result) const
bool getPropertyByName (const char *property_name, std::string &result) const
bool getPropertyByName (const char *property_name, std::vector< std::string > *&result) const
bool getPropertyByName (const char *property_name, std::string *&result) const
bool getPropertyByName (const char *property_name, IProperty *&result) const
bool getPropertyByName (const char *property_name, const IProperty *&result) const
virtual bool read (xmlNodePtr xmlNode, const char *filename, uint version, CLigoConfig &config)
void removeProperties ()
bool removeProperty (uint index)
bool removePropertyByName (const char *property_name)
virtual void write (xmlNodePtr xmlNode, const char *filename) const
void updateChildId (uint index)
uint _ChildId
std::vector< IPrimitive * > _Children
IPrimitive_Parent
std::map< std::string, IProperty * > _Properties

Hierarchy

bool getChild (IPrimitive *&result, uint childId)
bool getChild (const IPrimitive *&result, uint childId) const
bool getChildId (uint &childId, const IPrimitive *child) const
uint getNumChildren () const
const IPrimitivegetParent () const
IPrimitivegetParent ()
bool insertChild (IPrimitive *primitive, uint index=AtTheEnd)
 IPrimitive (const IPrimitive &node)
 IPrimitive ()
virtual void operator= (const IPrimitive &node)
bool removeChild (uint childId)
void removeChildren ()
virtual ~IPrimitive ()

Public Types

enum  { NotAnArray, AtTheEnd = 0xffffffff }

Public Member Functions

virtual std::string getClassName ()=0

Data Fields

bool Expanded
std::string Layer
std::string Name

Member Enumeration Documentation

anonymous enum
 

Enumeration values:
NotAnArray 
AtTheEnd 

Definition at line 165 of file primitive.h.

00166         {
00167                 NotAnArray,
00168                 AtTheEnd = 0xffffffff,
00169         };


Constructor & Destructor Documentation

NLLIGO::IPrimitive::IPrimitive  )  [inline]
 

Get a child primitive

Definition at line 172 of file primitive.h.

00173         {
00174                 _Parent = NULL;
00175         };

NLLIGO::IPrimitive::~IPrimitive  )  [virtual]
 

Get a child primitive

Definition at line 1373 of file primitive.cpp.

References removeChildren(), and removeProperties().

01374 {
01375         // Remove children
01376         removeChildren ();
01377 
01378         // Erase properties
01379         removeProperties ();
01380 }

NLLIGO::IPrimitive::IPrimitive const IPrimitive node  ) 
 

Get a child primitive

Definition at line 976 of file primitive.cpp.

00977 {
00978         _Parent = NULL;
00979         IPrimitive::operator= (node);
00980 }


Member Function Documentation

bool NLLIGO::IPrimitive::addPropertyByName const char *  property_name,
IProperty result
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Definition at line 1384 of file primitive.cpp.

References _Properties.

Referenced by NLLIGO::CPrimitives::convertAddPrimitive(), NLLIGO::CPrimitives::convertPrimitive(), and read().

01385 {
01386         bool inserted = _Properties.insert (std::map<std::string, IProperty*>::value_type (property_name, result)).second;
01387         if (inserted)
01388         {
01389                 return true;
01390         }
01391         return false;
01392 }

virtual IPrimitive* NLLIGO::IPrimitive::copy  )  const [pure virtual]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Implemented in NLLIGO::CPrimNode, NLLIGO::CPrimPoint, NLLIGO::CPrimPath, and NLLIGO::CPrimZone.

bool NLLIGO::IPrimitive::getChild IPrimitive *&  result,
uint  childId
 

Get a child primitive

Definition at line 1303 of file primitive.cpp.

References nlwarning, and uint.

01304 {
01305         if (childId < _Children.size ())
01306         {
01307                 result = _Children[childId];
01308                 return true;
01309         }
01310         else
01311         {
01312                 nlwarning ("NLLIGO::IPrimitive::getChild : invalid index (index : %d, size %d).", childId, _Children.size ());
01313         }
01314         return false;
01315 }

bool NLLIGO::IPrimitive::getChild const IPrimitive *&  result,
uint  childId
const
 

Get a child primitive

Definition at line 1287 of file primitive.cpp.

References nlwarning, and uint.

Referenced by NLLIGO::CPrimitives::convertPrimitive(), NLSOUND::CBackgroundSoundManager::loadAudioFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadEffectsFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadSamplesFromPrimitives(), and NLSOUND::CBackgroundSoundManager::loadSoundsFromPrimitives().

01288 {
01289         if (childId < _Children.size ())
01290         {
01291                 result = _Children[childId];
01292                 return true;
01293         }
01294         else
01295         {
01296                 nlwarning ("NLLIGO::IPrimitive::getChild : invalid index (index : %d, size %d).", childId, _Children.size ());
01297         }
01298         return false;
01299 }

bool NLLIGO::IPrimitive::getChildId uint childId,
const IPrimitive child
const
 

Get the id of the child, return 0xffffffff if not found

Definition at line 1713 of file primitive.cpp.

References _ChildId, and uint.

01714 {
01715         childId = child->_ChildId;
01716         return true;
01717 }

virtual std::string NLMISC::IClassable::getClassName  )  [pure virtual, inherited]
 

Implemented in NLAIAGENT::CNumericIndex, NLAIC::IPointerGestion, NLAIC::CIdentType, and CAutomataDesc.

Referenced by NLMISC::CClassRegistry::checkObject(), and NL3D::GetTextureSize().

uint NLLIGO::IPrimitive::getNumChildren  )  const [inline]
 

Get the children primitive count

Definition at line 183 of file primitive.h.

References uint.

Referenced by NLLIGO::CPrimitives::convertPrimitive(), NLSOUND::CBackgroundSoundManager::loadAudioFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadEffectsFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadSamplesFromPrimitives(), and NLSOUND::CBackgroundSoundManager::loadSoundsFromPrimitives().

00184         {
00185                 return _Children.size ();
00186         }

uint NLLIGO::IPrimitive::getNumProperty  )  const
 

Get a num properties

Definition at line 1721 of file primitive.cpp.

References _Properties, and uint.

01722 {
01723         return _Properties.size ();
01724 }

virtual uint NLLIGO::IPrimitive::getNumVector  )  const [pure virtual]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Implemented in NLLIGO::CPrimPoint, NLLIGO::CPrimPath, and NLLIGO::CPrimZone.

Referenced by NLSOUND::CBackgroundSoundManager::loadSoundsFromPrimitives().

const IPrimitive* NLLIGO::IPrimitive::getParent  )  const [inline]
 

Get a child primitive

Definition at line 199 of file primitive.h.

00200         {
00201                 return _Parent;
00202         }

IPrimitive* NLLIGO::IPrimitive::getParent  )  [inline]
 

Get the parent primtive

Definition at line 195 of file primitive.h.

Referenced by NLLIGO::CLigoConfig::canBeChild(), and NLLIGO::CLigoConfig::getPrimitiveClass().

00196         {
00197                 return _Parent;
00198         }

virtual CPrimVector* NLLIGO::IPrimitive::getPrimVector  )  [pure virtual]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Implemented in NLLIGO::CPrimNode, NLLIGO::CPrimPoint, NLLIGO::CPrimPath, and NLLIGO::CPrimZone.

virtual const CPrimVector* NLLIGO::IPrimitive::getPrimVector  )  const [pure virtual]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Implemented in NLLIGO::CPrimPoint, NLLIGO::CPrimPath, and NLLIGO::CPrimZone.

bool NLLIGO::IPrimitive::getProperty uint  index,
std::string &  property_name,
IProperty *&  result
 

Get a properties by its index This is method (iterate a list) is slower than getPropertyByName (look up in a map).

Definition at line 1081 of file primitive.cpp.

References _Properties, index, nlwarning, and uint.

01082 {
01083         // Look for the property
01084         std::map<std::string, IProperty*>::iterator ite = _Properties.begin ();
01085         while (ite != _Properties.end ())
01086         {
01087                 if (index == 0)
01088                 {
01089                         property_name = ite->first;
01090                         result = ite->second;
01091                         return true;
01092                 }
01093                 index--;
01094                 ite ++;
01095         }
01096         nlwarning ("NLLIGO::IPrimitive::getProperty : invalid index (index : %d, size : %d).", index, _Properties.size ());
01097         return false;
01098 }

bool NLLIGO::IPrimitive::getProperty uint  index,
std::string &  property_name,
const IProperty *&  result
const
 

Get a properties by its index This is method (iterate a list) is slower than getPropertyByName (look up in a map).

Definition at line 1060 of file primitive.cpp.

References _Properties, index, nlwarning, and uint.

01061 {
01062         // Look for the property
01063         std::map<std::string, IProperty*>::const_iterator ite = _Properties.begin ();
01064         while (ite != _Properties.end ())
01065         {
01066                 if (index == 0)
01067                 {
01068                         property_name = ite->first;
01069                         result = ite->second;
01070                         return true;
01071                 }
01072                 index--;
01073                 ite ++;
01074         }
01075         nlwarning ("NLLIGO::IPrimitive::getProperty : invalid index (index : %d, size : %d).", index, _Properties.size ());
01076         return false;
01077 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
NLMISC::CRGBA result
const
 

Get a color property with its name. Return false if the property is not found or is not a string array property.

Definition at line 1218 of file primitive.cpp.

References NLLIGO::CPropertyColor::Color, getPropertyByName(), and nlwarning.

01219 {
01220         // Get the property
01221         IProperty *prop;
01222         if (getPropertyByName (property_name, prop))
01223         {
01224                 const CPropertyColor *colorProp = dynamic_cast<const CPropertyColor *> (prop);
01225                 if (colorProp)
01226                 {
01227                         result = colorProp->Color;
01228                         return true;
01229                 }
01230                 else
01231                 {
01232                         nlwarning ("NLLIGO::IPrimitive::getPropertyByName : property (%s) in not a color.", property_name);
01233                 }
01234         }
01235         return false;
01236 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
const std::vector< std::string > *&  result
const
 

Get a string array property with its name. Return false if the property is not found or is not a string array property.

Definition at line 1196 of file primitive.cpp.

References getPropertyByName(), nlwarning, and NLLIGO::CPropertyStringArray::StringArray.

01197 {
01198         // Get the property
01199         IProperty *prop;
01200         if (getPropertyByName (property_name, prop))
01201         {
01202                 const CPropertyStringArray *strProp = dynamic_cast<const CPropertyStringArray *> (prop);
01203                 if (strProp)
01204                 {
01205                         result = &(strProp->StringArray);
01206                         return true;
01207                 }
01208                 else
01209                 {
01210                         nlwarning ("NLLIGO::IPrimitive::getPropertyByName : property (%s) in not a string.", property_name);
01211                 }
01212         }
01213         return false;
01214 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
std::string &  result
const
 

Get a string property with its name. Return false if the property is not found or is not a string property.

Definition at line 1152 of file primitive.cpp.

References getPropertyByName(), nlwarning, and NLLIGO::CPropertyString::String.

01153 {
01154         // Get the property
01155         const IProperty *prop;
01156         if (getPropertyByName (property_name, prop))
01157         {
01158                 const CPropertyString *strProp = dynamic_cast<const CPropertyString *> (prop);
01159                 if (strProp)
01160                 {
01161                         result = strProp->String;
01162                         return true;
01163                 }
01164                 else
01165                 {
01166                         nlwarning ("NLLIGO::IPrimitive::getPropertyByName : property (%s) in not a string.", property_name);
01167                 }
01168         }
01169         return false;
01170 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
std::vector< std::string > *&  result
const
 

Get a string array property with its name. Return false if the property is not found or is not a string array property.

Definition at line 1174 of file primitive.cpp.

References getPropertyByName(), nlwarning, and NLLIGO::CPropertyStringArray::StringArray.

01175 {
01176         // Get the property
01177         IProperty *prop;
01178         if (getPropertyByName (property_name, prop))
01179         {
01180                 CPropertyStringArray *strProp = dynamic_cast<CPropertyStringArray *> (prop);
01181                 if (strProp)
01182                 {
01183                         result = &(strProp->StringArray);
01184                         return true;
01185                 }
01186                 else
01187                 {
01188                         nlwarning ("NLLIGO::IPrimitive::getPropertyByName : property (%s) in not a string.", property_name);
01189                 }
01190         }
01191         return false;
01192 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
std::string *&  result
const
 

Get a string property with its name. Return false if the property is not found or is not a string property.

Definition at line 1130 of file primitive.cpp.

References getPropertyByName(), nlwarning, and NLLIGO::CPropertyString::String.

01131 {
01132         // Get the property
01133         IProperty *prop;
01134         if (getPropertyByName (property_name, prop))
01135         {
01136                 CPropertyString *strProp = dynamic_cast<CPropertyString *> (prop);
01137                 if (strProp)
01138                 {
01139                         result = &(strProp->String);
01140                         return true;
01141                 }
01142                 else
01143                 {
01144                         nlwarning ("NLLIGO::IPrimitive::getPropertyByName : property (%s) in not a string.", property_name);
01145                 }
01146         }
01147         return false;
01148 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
IProperty *&  result
const
 

Get a property with its name

Definition at line 1116 of file primitive.cpp.

References _Properties.

01117 {
01118         // Look for the property
01119         std::map<std::string, IProperty*>::const_iterator ite = _Properties.find (property_name);
01120         if (ite != _Properties.end ())
01121         {
01122                 result = ite->second;
01123                 return true;
01124         }
01125         return false;
01126 }

bool NLLIGO::IPrimitive::getPropertyByName const char *  property_name,
const IProperty *&  result
const
 

Get a property with its name

Definition at line 1102 of file primitive.cpp.

References _Properties.

Referenced by NLLIGO::CPrimitiveConfigurations::belong(), NLLIGO::CLigoConfig::canBeChild(), NLLIGO::CLigoConfig::canBeRoot(), NLLIGO::CPrimitives::convertPrimitive(), NLLIGO::CLigoConfig::getPrimitiveClass(), NLLIGO::CLigoConfig::getPrimitiveColor(), getPropertyByName(), NLLIGO::CLigoConfig::isPrimitiveDeletable(), NLLIGO::CLigoConfig::isPrimitiveLinked(), NLSOUND::CBackgroundSoundManager::loadAudioFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadEffectsFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadSamplesFromPrimitives(), NLSOUND::CBackgroundSoundManager::loadSoundsFromPrimitives(), read(), and NLLIGO::CPrimitiveClass::CParameter::translateAutoname().

01103 {
01104         // Look for the property
01105         std::map<std::string, IProperty*>::const_iterator ite = _Properties.find (property_name);
01106         if (ite != _Properties.end ())
01107         {
01108                 result = ite->second;
01109                 return true;
01110         }
01111         return false;
01112 }

bool NLLIGO::IPrimitive::insertChild IPrimitive primitive,
uint  index = AtTheEnd
 

Insert a child primitive before the index. The pointer will be deleted by the parent primitive using the ::delete operator. return false if the index is invalid

Definition at line 1349 of file primitive.cpp.

References _Parent, AtTheEnd, index, uint, and updateChildId().

Referenced by NLLIGO::CPrimitives::convertAddPrimitive(), NLLIGO::CPrimitives::convertPrimitive(), and read().

01350 {
01351         // At the end ?
01352         if (index == AtTheEnd)
01353                 index = _Children.size ();
01354 
01355         // Index valid ?
01356         if (index>_Children.size ())
01357                 return false;
01358 
01359         // Insert
01360         _Children.insert (_Children.begin () + index, primitive);
01361 
01362         // Update child id
01363         updateChildId (index);
01364 
01365         // Link to the parent
01366         primitive->_Parent = this;
01367 
01368         return true;
01369 }

void NLLIGO::IPrimitive::operator= const IPrimitive node  )  [virtual]
 

Get a child primitive

Definition at line 994 of file primitive.cpp.

References _ChildId, _Children, _Properties, Expanded, Layer, Name, nlverify, removeChildren(), removeProperties(), and uint.

00995 {
00996         // Clean dest
00997         removeChildren ();
00998         removeProperties ();
00999 
01000         // copy deprecated param
01001         Layer = node.Layer;
01002         Name = node.Name;
01003 
01004         // Copy the flags
01005         Expanded = node.Expanded;
01006         _ChildId = node._ChildId;
01007 
01008         // Copy children
01009         _Children.resize (node._Children.size ());
01010         for (uint child = 0; child < node._Children.size (); child++)
01011         {
01012                 // Copy the child
01013                 _Children[child] = node._Children[child]->copy ();
01014 
01015                 // Set the parent
01016                 _Children[child]->_Parent = this;
01017         }
01018 
01019         // Copy properties
01020         std::map<std::string, IProperty*>::const_iterator ite = node._Properties.begin ();
01021         while (ite != node._Properties.end ())
01022         {
01023                 // Get the property
01024                 CPropertyString *propString = dynamic_cast<CPropertyString *>(ite->second);
01025                 if (propString)
01026                 {
01027                         // New property
01028                         CPropertyString *newProp = new CPropertyString ();
01029                         *newProp = *propString;
01030                         _Properties.insert (std::map<std::string, IProperty*>::value_type (ite->first, newProp));
01031                 }
01032                 else
01033                 {
01034                         CPropertyStringArray *propStringArray = dynamic_cast<CPropertyStringArray *>(ite->second);
01035                         if (propStringArray)
01036                         {
01037                                 // New property
01038                                 CPropertyStringArray *newProp = new CPropertyStringArray ();
01039                                 *newProp = *propStringArray;
01040                                 _Properties.insert (std::map<std::string, IProperty*>::value_type (ite->first, newProp));
01041                         }
01042                         else
01043                         {
01044                                 CPropertyColor *propColor = dynamic_cast<CPropertyColor *>(ite->second);
01045                                 nlverify (propColor);
01046 
01047                                 // New property
01048                                 CPropertyColor *newProp = new CPropertyColor ();
01049                                 *newProp = *propColor;
01050                                 _Properties.insert (std::map<std::string, IProperty*>::value_type (ite->first, newProp));
01051                         }
01052                 }
01053 
01054                 ite++;
01055         }
01056 }

bool NLLIGO::IPrimitive::read xmlNodePtr  xmlNode,
const char *  filename,
uint  version,
CLigoConfig config
[virtual]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Reimplemented in NLLIGO::CPrimNode, NLLIGO::CPrimPoint, NLLIGO::CPrimPath, and NLLIGO::CPrimZone.

Definition at line 1396 of file primitive.cpp.

References _Properties, addPropertyByName(), NLMISC::clamp(), count, NLLIGO::IProperty::Default, Expanded, NLLIGO::GetContentString(), NLLIGO::CPrimitiveClass::CParameter::getDefaultValue(), NLLIGO::GetNodeString(), NLLIGO::CLigoConfig::getPrimitiveClass(), getPropertyByName(), NLLIGO::GetPropertyString(), insertChild(), NLLIGO::CPrimitiveClass::CInitParameters::Name, nlverify, NLLIGO::CPrimitiveClass::Parameters, sint32, NLLIGO::CPropertyString::String, NLLIGO::CPropertyStringArray::StringArray, NLLIGO::CPrimitiveClass::CParameter::Type, type, uint, uint8, and NLLIGO::XMLError().

01397 {
01398         // Erase old properties
01399         _Properties.clear ();
01400 
01401         // Read the expanded flag
01402         string expanded;
01403         Expanded = true;
01404         if (CIXml::getPropertyString (expanded, xmlNode, "EXPANDED"))
01405                 Expanded = (expanded != "false");
01406 
01407         // Read the properties
01408         xmlNodePtr propNode;
01409         propNode = CIXml::getFirstChildNode (xmlNode, "PROPERTY");
01410         if (propNode)
01411         {
01412                 do
01413                 {
01414                         // Read the name
01415                         string name;
01416                         if (GetNodeString (name, filename, propNode, "NAME"))
01417                         {
01418                                 // Get the property type
01419                                 string type;
01420                                 if (GetPropertyString (type, filename, propNode, "TYPE"))
01421                                 {
01422                                         // The property
01423                                         IProperty *property = NULL;
01424 
01425                                         // Check the type
01426                                         if (type == "string")
01427                                         {
01428                                                 // Create a new property
01429                                                 CPropertyString *propertyString = new CPropertyString;
01430                                                 property = propertyString;
01431                                                 
01432                                                 // Read it
01433                                                 if (!GetNodeString (propertyString->String, filename, propNode, "STRING"))
01434                                                 {
01435                                                         return false;
01436                                                 }
01437                                         }
01438                                         else if (type == "string_array")
01439                                         {
01440                                                 // Create a new property
01441                                                 CPropertyStringArray *propertyStringArray = new CPropertyStringArray;
01442                                                 property = propertyStringArray;
01443 
01444                                                 // Read strings
01445                                                 xmlNodePtr stringNode;
01446                                                 propertyStringArray->StringArray.reserve (CIXml::countChildren (propNode, "STRING"));
01447                                                 stringNode = CIXml::getFirstChildNode (propNode, "STRING");
01448                                                 if (stringNode)
01449                                                 {
01450                                                         do
01451                                                         {
01452                                                                 // Add the string
01453                                                                 string content;
01454                                                                 GetContentString (content, filename, stringNode);
01455                                                                 propertyStringArray->StringArray.push_back (content);
01456                                                         }
01457                                                         while ((stringNode = CIXml::getNextChildNode (stringNode, "STRING")));
01458                                                 }
01459                                         }
01460                                         else if (type == "color")
01461                                         {
01462                                                 // Create a new property
01463                                                 CPropertyColor *propertyColor= new CPropertyColor;
01464                                                 property = propertyColor;
01465 
01466                                                 // Read strings
01467                                                 xmlNodePtr colorNode;
01468                                                 colorNode = CIXml::getFirstChildNode (xmlNode, "COLOR");
01469                                                 string R, G, B, A;
01470                                                 if (GetPropertyString (R, filename, colorNode, "R") &&
01471                                                         GetPropertyString (G, filename, colorNode, "G") &&
01472                                                         GetPropertyString (B, filename, colorNode, "B") &&
01473                                                         GetPropertyString (A, filename, colorNode, "A"))
01474                                                 {
01475                                                         sint32 sR=0, sG=0, sB=0, sA=255;
01476                                                         sR = atoi (R.c_str ());
01477                                                         clamp (sR, 0, 255);
01478                                                         sG = atoi (G.c_str ());
01479                                                         clamp (sG, 0, 255);
01480                                                         sB = atoi (B.c_str ());
01481                                                         clamp (sB, 0, 255);
01482                                                         sA = atoi (A.c_str ());
01483                                                         clamp (sR, 0, 255);
01484                                                         propertyColor->Color.R = (uint8)sR;
01485                                                         propertyColor->Color.G = (uint8)sG;
01486                                                         propertyColor->Color.B = (uint8)sB;
01487                                                         propertyColor->Color.A = (uint8)sA;
01488                                                 }
01489                                                 else
01490                                                         return false;
01491                                         }
01492 
01493                                         // Property found ?
01494                                         if (property == NULL)
01495                                         {
01496                                                 XMLError (propNode, filename, "IPrimitive::read : Unknown property type (%s)", type.c_str ());
01497                                                 return false;
01498                                         }
01499 
01500                                         // Add it
01501                                         _Properties.insert (std::map<std::string, IProperty*>::value_type (name, property));
01502                                 }
01503                                 else
01504                                 {
01505                                         return false;
01506                                 }
01507                         }
01508                         else
01509                         {
01510                                 return false;
01511                         }
01512                 }
01513                 while ((propNode = CIXml::getNextChildNode (propNode, "PROPERTY")));
01514         }
01515 
01516         // Get the primitive class
01517         const CPrimitiveClass *primitiveClass = config.getPrimitiveClass (*this);
01518         if (primitiveClass)
01519         {
01520                 // For each properties
01521                 uint count = primitiveClass->Parameters.size ();
01522                 uint i;
01523                 for (i=0; i<count; i++)
01524                 {
01525                         const CPrimitiveClass::CParameter &parameter = primitiveClass->Parameters[i];
01526                         
01527                         // Get the property
01528                         IProperty *result;
01529                         if (!getPropertyByName (parameter.Name.c_str(), result))
01530                         {
01531                                 // Create the property
01532                                 if ((parameter.Type == CPrimitiveClass::CParameter::StringArray) || (parameter.Type == CPrimitiveClass::CParameter::ConstStringArray))
01533                                         result = new CPropertyStringArray();
01534                                 else
01535                                         result = new CPropertyString();
01536                                 nlverify (addPropertyByName (parameter.Name.c_str(), result));
01537                         }
01538                 }
01539                         
01540                 // Set the default values
01541                 for (i=0; i<count; i++)
01542                 {
01543                         const CPrimitiveClass::CParameter &parameter = primitiveClass->Parameters[i];
01544 
01545                         CPropertyString *pString = NULL;
01546                         CPropertyStringArray *pStringArray = NULL;
01547 
01548                         IProperty *result;
01549                         nlverify (getPropertyByName (parameter.Name.c_str(), result));
01550                         pString = dynamic_cast<CPropertyString*>(result);
01551                         if (!pString)
01552                                 pStringArray = dynamic_cast<CPropertyStringArray*>(result);
01553 
01554                         // Property have default values ?
01555                         if (pString)
01556                         {
01557                                 // Empty string ?
01558                                 if (pString->String.empty())
01559                                 {
01560                                         // Set as default
01561                                         pString->Default = true;
01562                                         parameter.getDefaultValue (pString->String, *this, *primitiveClass);
01563                                 }
01564                         }
01565                         else if (pStringArray)
01566                         {
01567                                 // Empty string array ?
01568                                 if (pStringArray->StringArray.empty())
01569                                 {
01570                                         // Set as default
01571                                         pStringArray->Default = true;
01572                                         parameter.getDefaultValue (pStringArray->StringArray, *this, *primitiveClass);
01573                                 }
01574                         }
01575                 }
01576         }
01577 
01578         // Read children
01579         xmlNodePtr childNode;
01580         childNode = CIXml::getFirstChildNode (xmlNode, "CHILD");
01581         if (childNode)
01582         {
01583                 do
01584                 {
01585                         // Get the property class
01586                         string type;
01587                         if (GetPropertyString (type, filename, childNode, "TYPE"))
01588                         {
01589                                 // Primitive
01590                                 if (type=="node")
01591                                         type="CPrimNode";
01592                                 if (type=="point")
01593                                         type="CPrimPoint";
01594                                 if (type=="path")
01595                                         type="CPrimPath";
01596                                 if (type=="zone")
01597                                         type="CPrimZone";
01598                                 IPrimitive *primitive = static_cast<IPrimitive *> (CClassRegistry::create (type));
01599 
01600                                 // Primitive type not found ?
01601                                 if (primitive == NULL)
01602                                 {
01603                                         XMLError (childNode, filename, "IPrimitive::read : Unknown primitive type (%s)", type.c_str ());
01604                                         return false;
01605                                 }
01606 
01607                                 // Read it
01608                                 primitive->read (childNode, filename, version, config);
01609 
01610                                 // Add it
01611                                 insertChild (primitive);
01612                         }
01613                         else
01614                         {
01615                                 return false;
01616                         }
01617                 }
01618                 while ((childNode = CIXml::getNextChildNode (childNode, "CHILD")));
01619         }
01620 
01621         // Done
01622         return true;
01623 }

bool NLLIGO::IPrimitive::removeChild uint  childId  ) 
 

Remove a child primitive

Definition at line 1319 of file primitive.cpp.

References nlwarning, uint, and updateChildId().

01320 {
01321         if (childId < _Children.size ())
01322         {
01323                 delete _Children[childId];
01324                 _Children.erase (_Children.begin()+childId);
01325                 updateChildId (childId);
01326                 return true;
01327         }
01328         else
01329         {
01330                 nlwarning ("NLLIGO::IPrimitive::removeChild : invalid index (index : %d, size %d).", childId, _Children.size ());
01331         }
01332         return false;
01333 }

void NLLIGO::IPrimitive::removeChildren  ) 
 

Remove all children primitives

Definition at line 1337 of file primitive.cpp.

References uint.

Referenced by NLLIGO::CPrimitives::convert(), operator=(), NLLIGO::CPrimitives::read(), and ~IPrimitive().

01338 {
01339         // Erase children
01340         for (uint i=0; i<_Children.size (); i++)
01341         {
01342                 delete _Children[i];
01343         }
01344         _Children.clear ();
01345 }

void NLLIGO::IPrimitive::removeProperties  ) 
 

Remove all the properties

Definition at line 1274 of file primitive.cpp.

References _Properties.

Referenced by NLLIGO::CPrimitives::convert(), operator=(), NLLIGO::CPrimitives::read(), and ~IPrimitive().

01275 {
01276         std::map<std::string, IProperty*>::iterator ite = _Properties.begin ();
01277         while (ite != _Properties.end ())
01278         {
01279                 delete ite->second;
01280                 ite++;
01281         }
01282         _Properties.clear ();
01283 }

bool NLLIGO::IPrimitive::removeProperty uint  index  ) 
 

Remove a property This is method (iterate a list) is slower than removePropertyByName (look up in a map).

Definition at line 1240 of file primitive.cpp.

References _Properties, index, nlwarning, and uint.

01241 {
01242         // Look for the property
01243         std::map<std::string, IProperty*>::iterator ite = _Properties.begin ();
01244         while (ite != _Properties.end ())
01245         {
01246                 if (index == 0)
01247                 {
01248                         _Properties.erase (ite);
01249                         return true;
01250                 }
01251                 index--;
01252                 ite ++;
01253         }
01254         nlwarning ("NLLIGO::IPrimitive::removeProperty : invalid index (index : %d, size : %d).", index, _Properties.size ());
01255         return false;
01256 }

bool NLLIGO::IPrimitive::removePropertyByName const char *  property_name  ) 
 

Remove a property by its name

Definition at line 1260 of file primitive.cpp.

References _Properties.

01261 {
01262         // Look for the property
01263         std::map<std::string, IProperty*>::iterator ite = _Properties.find (property_name);
01264         if (ite != _Properties.end ())
01265         {
01266                 _Properties.erase (ite);
01267                 return true;
01268         }
01269         return false;
01270 }

void NLLIGO::IPrimitive::updateChildId uint  index  )  [private]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Definition at line 984 of file primitive.cpp.

References count, index, and uint.

Referenced by insertChild(), and removeChild().

00985 {
00986         uint i;
00987         uint count = _Children.size ();
00988         for (i=index; i<count; i++)
00989                 _Children[i]->_ChildId = i;
00990 }

void NLLIGO::IPrimitive::write xmlNodePtr  xmlNode,
const char *  filename
const [virtual]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Reimplemented in NLLIGO::CPrimPoint, NLLIGO::CPrimPath, and NLLIGO::CPrimZone.

Definition at line 1627 of file primitive.cpp.

References _Properties, NLMISC::CRGBA::A, NLMISC::CRGBA::B, NLLIGO::CPropertyColor::Color, Expanded, NLMISC::CRGBA::G, NLMISC::CRGBA::R, NLLIGO::CPropertyString::String, NLLIGO::CPropertyStringArray::StringArray, NLMISC::toString(), and uint.

01628 {
01629         // Save the expanded flag
01630         if (!Expanded)
01631                 xmlSetProp (xmlNode, (const xmlChar*)"EXPANDED", (const xmlChar*)"false");
01632 
01633         // Set the type
01634         xmlSetProp (xmlNode, (const xmlChar*)"TYPE", (const xmlChar*)(const_cast<IPrimitive*> (this)->getClassName ().c_str ()));
01635 
01636         // Save the properties
01637         std::map<std::string, IProperty*>::const_iterator ite = _Properties.begin ();
01638         while (ite != _Properties.end ())
01639         {
01640                 // Not a default property ?
01641                 if (!ite->second->Default)
01642                 {
01643                         // Create new nodes
01644                         xmlNodePtr propNode = xmlNewChild ( xmlNode, NULL, (const xmlChar*)"PROPERTY", NULL);
01645                         xmlNodePtr nameNode = xmlNewChild ( propNode, NULL, (const xmlChar*)"NAME", NULL);
01646                         xmlNodePtr textNode = xmlNewText ((const xmlChar *)(ite->first.c_str ()));
01647                         xmlAddChild (nameNode, textNode);
01648 
01649                         // Type
01650                         const CPropertyString *str = dynamic_cast<const CPropertyString *> (ite->second);
01651                         if (str)
01652                         {
01653                                 // Set the type
01654                                 xmlSetProp (propNode, (const xmlChar*)"TYPE", (const xmlChar*)"string");
01655 
01656                                 // Create new nodes
01657                                 xmlNodePtr stringNode = xmlNewChild ( propNode, NULL, (const xmlChar*)"STRING", NULL);
01658                                 xmlNodePtr textNode = xmlNewText ((const xmlChar *)(str->String.c_str ()));
01659                                 xmlAddChild (stringNode, textNode);
01660                         }
01661                         else
01662                         {
01663                                 // Should be an array
01664                                 const CPropertyStringArray *array = dynamic_cast<const CPropertyStringArray *> (ite->second);
01665                                 if (array)
01666                                 {
01667                                         // Set the type
01668                                         xmlSetProp (propNode, (const xmlChar*)"TYPE", (const xmlChar*)"string_array");
01669 
01670                                         // For each strings in the array
01671                                         for (uint i=0; i<array->StringArray.size (); i++)
01672                                         {
01673                                                 // Create new nodes
01674                                                 xmlNodePtr stringNode = xmlNewChild ( propNode, NULL, (const xmlChar*)"STRING", NULL);
01675                                                 xmlNodePtr textNode = xmlNewText ((const xmlChar *)(array->StringArray[i].c_str ()));
01676                                                 xmlAddChild (stringNode, textNode);
01677                                         }
01678                                 }
01679                                 else
01680                                 {
01681                                         // Should be a color
01682                                         const CPropertyColor *color = safe_cast<const CPropertyColor *> (ite->second);
01683 
01684                                         // Set the type
01685                                         xmlSetProp (propNode, (const xmlChar*)"TYPE", (const xmlChar*)"color");
01686 
01687                                         // Create new nodes
01688                                         xmlNodePtr colorNode = xmlNewChild ( propNode, NULL, (const xmlChar*)"COLOR", NULL);
01689                                         xmlSetProp (colorNode, (const xmlChar*)"R", (const xmlChar*)toString (color->Color.R).c_str ());
01690                                         xmlSetProp (colorNode, (const xmlChar*)"G", (const xmlChar*)toString (color->Color.G).c_str ());
01691                                         xmlSetProp (colorNode, (const xmlChar*)"B", (const xmlChar*)toString (color->Color.B).c_str ());
01692                                         xmlSetProp (colorNode, (const xmlChar*)"A", (const xmlChar*)toString (color->Color.A).c_str ());
01693                                 }
01694                         }
01695                 }
01696 
01697                 ite++;
01698         }
01699 
01700         // Save the children
01701         for (uint i=0; i<_Children.size (); i++)
01702         {
01703                 // New node
01704                 xmlNodePtr childNode = xmlNewChild ( xmlNode, NULL, (const xmlChar*)"CHILD", NULL);
01705 
01706                 // Write it
01707                 _Children[i]->write (childNode, filename);
01708         }
01709 }


Field Documentation

uint NLLIGO::IPrimitive::_ChildId [private]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Definition at line 317 of file primitive.h.

Referenced by getChildId(), and operator=().

std::vector<IPrimitive*> NLLIGO::IPrimitive::_Children [private]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Definition at line 323 of file primitive.h.

Referenced by operator=().

IPrimitive* NLLIGO::IPrimitive::_Parent [private]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Definition at line 320 of file primitive.h.

Referenced by insertChild().

std::map<std::string, IProperty*> NLLIGO::IPrimitive::_Properties [private]
 

Add a property If the property already exist, the method does nothing and returns false. The pointer will be deleted by the primitive using the ::delete operator.

Definition at line 326 of file primitive.h.

Referenced by addPropertyByName(), getNumProperty(), getProperty(), getPropertyByName(), operator=(), read(), removeProperties(), removeProperty(), removePropertyByName(), and write().

bool NLLIGO::IPrimitive::Expanded
 

Definition at line 163 of file primitive.h.

Referenced by operator=(), read(), and write().

std::string NLLIGO::IPrimitive::Layer
 

Definition at line 159 of file primitive.h.

Referenced by NLLIGO::CPrimitives::convertPrimitive(), and operator=().

std::string NLLIGO::IPrimitive::Name
 

Definition at line 160 of file primitive.h.

Referenced by NLLIGO::CPrimitives::convertAddPrimitive(), and operator=().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 12:52:39 2004 for NeL by doxygen 1.3.6