00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __DAE_ELEMENT_H__
00010 #define __DAE_ELEMENT_H__
00011 #include <string>
00012 #include <dae/daeTypes.h>
00013 #include <dae/daeMemorySystem.h>
00014 #include <wchar.h>
00015 #include <dae/daeArray.h>
00016 #include <dae/daeRefCountedObj.h>
00017 #include <dae/daeSmartRef.h>
00018
00019
00020
00021
00022
00023 namespace COLLADA_TYPE
00024 {
00025 typedef int TypeEnum;
00026 }
00027
00028 class DAE;
00029 class daeMetaElement;
00030 class daeMetaAttribute;
00031 class daeDocument;
00032 class daeURI;
00033
00043 class DLLSPEC daeElement : public daeRefCountedObj
00044 {
00045 public:
00049 DAE_ALLOC
00050 protected:
00051 daeElement* _parent;
00052 daeDocument* _document;
00053 daeMetaElement* _meta;
00054 daeString _elementName;
00055 daeBoolArray _validAttributeArray;
00056 void* _userData;
00057
00058 protected:
00059 daeElement( const daeElement &cpy ) : daeRefCountedObj() { (void)cpy; };
00060 virtual daeElement &operator=( const daeElement &cpy ) { (void)cpy; return *this; }
00061
00062 void init();
00063
00064
00065 void setDocument( daeDocument* c, bool notifyDocument );
00066 daeElement* simpleAdd(daeString name, int index = -1);
00067
00068 public:
00074 daeElement();
00080 daeElement(DAE& dae);
00081
00087 virtual ~daeElement();
00088
00094 void setup(daeMetaElement* meta);
00095
00096
00097
00098 daeElement* add(daeString name, int index = -1);
00099 daeElement* add(daeElement* elt, int index = -1);
00100 daeElement* addBefore(daeElement* elt, daeElement* index);
00101 daeElement* addAfter(daeElement* elt, daeElement* index);
00102
00103
00104 daeElement* createAndPlace(daeString elementName);
00105 daeElement* createAndPlaceAt(daeInt index, daeString elementName);
00106 daeBool placeElement(daeElement* element);
00107 daeBool placeElementAt(daeInt index, daeElement* element);
00108 daeBool placeElementBefore( daeElement* marker, daeElement *element );
00109 daeBool placeElementAfter( daeElement* marker, daeElement *element );
00110
00117 daeInt findLastIndexOf( daeString elementName );
00118
00129 daeBool removeChildElement(daeElement* element);
00130
00145 static daeBool removeFromParent(daeElement* element)
00146 {
00147 if(element != NULL && element->_parent != NULL)
00148 return(element->_parent->removeChildElement(element));
00149 return false;
00150 };
00151
00156 size_t getAttributeCount();
00157
00164 daeMetaAttribute* getAttributeObject(daeString name);
00165
00171 daeMetaAttribute* getAttributeObject(size_t i);
00172
00178 std::string getAttributeName(size_t i);
00179
00185 daeBool hasAttribute(daeString name);
00186
00194 daeBool isAttributeSet(daeString name);
00195
00202 std::string getAttribute(daeString name);
00203
00211 void getAttribute(daeString name, std::string& value);
00212
00218 std::string getAttribute(size_t i);
00219
00226 void getAttribute(size_t i, std::string& value);
00227
00228 struct DLLSPEC attr {
00229 attr();
00230 attr(const std::string& name, const std::string& value);
00231
00232 std::string name;
00233 std::string value;
00234 };
00235
00240 daeTArray<attr> getAttributes();
00241
00247 void getAttributes(daeTArray<attr>& attrs);
00248
00255 virtual daeBool setAttribute(daeString name, daeString value);
00256
00263 virtual daeBool setAttribute(size_t i, daeString value);
00264
00270 daeMetaAttribute* getCharDataObject();
00271
00276 daeBool hasCharData();
00277
00283 std::string getCharData();
00284
00290 void getCharData(std::string& data);
00291
00298 daeBool setCharData(const std::string& data);
00299
00300
00301 daeMemoryRef getAttributeValue(daeString name);
00302 daeBool hasValue();
00303 daeMemoryRef getValuePointer();
00304
00310 daeDocument* getDocument() const { return _document; }
00311
00315 daeDocument* getCollection() const { return _document; }
00316
00321 DAE* getDAE();
00322
00327 void setDocument(daeDocument* c) { setDocument( c, true ); }
00331 void setCollection(daeDocument* c );
00332
00337 daeURI* getDocumentURI() const;
00338
00345 daeSmartRef<daeElement> createElement(daeString elementName);
00346
00352 daeElement* getParentElement() { return _parent;}
00357 daeElement* getXMLParentElement() { return _parent;}
00363 void setParentElement( daeElement *parent ) { _parent = parent; }
00364
00365
00366
00367
00368 struct DLLSPEC matchElement {
00369 virtual bool operator()(daeElement* elt) const = 0;
00370 virtual ~matchElement() { };
00371 };
00372
00373
00374 struct DLLSPEC matchName : public matchElement {
00375 matchName(daeString name);
00376 virtual bool operator()(daeElement* elt) const;
00377 std::string name;
00378 };
00379
00380
00381 struct DLLSPEC matchType : public matchElement {
00382 matchType(daeInt typeID);
00383 virtual bool operator()(daeElement* elt) const;
00384 daeInt typeID;
00385 };
00386
00387
00388
00389
00390 daeElement* getChild(const matchElement& matcher);
00391
00392
00393
00394 daeElement* getDescendant(const matchElement& matcher);
00395
00396
00397 daeElement* getParent();
00398
00399
00400 daeElement* getAncestor(const matchElement& matcher);
00401
00402
00403
00404
00405
00406 daeElement* getChild(daeString eltName);
00407 daeElement* getDescendant(daeString eltName);
00408 daeElement* getAncestor(daeString eltName);
00409
00416 inline daeMetaElement* getMeta() { return _meta; }
00417
00418
00419 virtual COLLADA_TYPE::TypeEnum getElementType() const { return (COLLADA_TYPE::TypeEnum)0; }
00420 daeString getTypeName() const;
00421
00427 virtual daeInt typeID() const = 0;
00428
00434 daeString getElementName() const;
00440 void setElementName( daeString nm );
00441
00448 daeString getID() const;
00449
00457 daeTArray< daeSmartRef<daeElement> > getChildren();
00458
00464
00465 void getChildren( daeTArray<daeSmartRef<daeElement> > &array );
00466
00471 template<typename T>
00472 daeTArray< daeSmartRef<T> > getChildrenByType() {
00473 daeTArray< daeSmartRef<T> > result;
00474 getChildrenByType(result);
00475 return result;
00476 }
00477
00483 template<typename T>
00484 void getChildrenByType(daeTArray< daeSmartRef<T> >& matchingChildren) {
00485 matchingChildren.setCount(0);
00486 daeTArray< daeSmartRef<daeElement> > children;
00487 getChildren(children);
00488 for (size_t i = 0; i < children.getCount(); i++)
00489 if (children[i]->typeID() == T::ID())
00490 matchingChildren.append((T*)children[i].cast());
00491 }
00492
00501 daeSmartRef<daeElement> clone( daeString idSuffix = NULL, daeString nameSuffix = NULL );
00502
00503
00504 struct DLLSPEC compareResult {
00505 int compareValue;
00506
00507
00508 daeElement* elt1;
00509 daeElement* elt2;
00510 bool nameMismatch;
00511 std::string attrMismatch;
00512 bool charDataMismatch;
00513 bool childCountMismatch;
00514
00515 compareResult();
00516 std::string format();
00517 };
00518
00519
00520
00521
00522
00523 static int compare(daeElement& elt1, daeElement& elt2);
00524
00525
00526 static compareResult compareWithFullResult(daeElement& elt1, daeElement& elt2);
00527
00532 void setUserData(void* data);
00533
00538 void* getUserData();
00539
00540 public:
00541
00542 static void deleteCMDataArray(daeTArray<daeCharArray*>& cmData);
00543 };
00544
00545 #include <dae/daeSmartRef.h>
00546 typedef daeSmartRef<daeElement> daeElementRef;
00547 typedef daeSmartRef<const daeElement> daeElementConstRef;
00548
00549 typedef daeTArray<daeElementRef> daeElementRefArray;
00550
00551 #endif //__DAE_ELEMENT_H__