1 /*
2 * Copyright 2006 Sony Computer Entertainment Inc.
3 *
4 * Licensed under the MIT Open Source License, for details please see license.txt or the website
5 * http://www.opensource.org/licenses/mit-license.php
6 *
7 */
8
9 #include <dae.h>
10 #include <dae/daeDom.h>
11 #include <dae/domAny.h>
12 #include <dae/daeMetaAttribute.h>
13 #include <dae/daeMetaCMPolicy.h>
14 #include <dae/daeMetaSequence.h>
15 #include <dae/daeMetaChoice.h>
16 #include <dae/daeMetaGroup.h>
17 #include <dae/daeMetaAny.h>
18 #include <dae/daeMetaElementAttribute.h>
19 #include <dae/daeErrorHandler.h>
20
21 daeElementRef
create(DAE & dae)22 domAny::create(DAE& dae)
23 {
24 domAnyRef ref = new domAny;
25 return ref;
26 }
27
28
29 daeMetaElement *
registerElement(DAE & dae)30 domAny::registerElement(DAE& dae)
31 {
32 daeMetaElement *_Meta = new daeMetaElement(dae);
33 _Meta->setName( "any" );
34 _Meta->registerClass(domAny::create);
35 _Meta->setIsInnerClass( true );
36
37 daeMetaCMPolicy *cm = NULL;
38 cm = new daeMetaSequence( _Meta, cm, 0, 1, 1 );
39
40 cm = new daeMetaAny( _Meta, cm, 0, 0, -1 );
41 cm->getParent()->appendChild( cm );
42 cm = cm->getParent();
43
44 cm->setMaxOrdinal( 0 );
45 _Meta->setCMRoot( cm );
46 _Meta->setAllowsAny( true );
47
48 _Meta->addContents(daeOffsetOf(domAny,_contents));
49 _Meta->addContentsOrder(daeOffsetOf(domAny,_contentsOrder));
50
51 //VALUE
52 {
53 daeMetaAttribute *ma = new daeMetaAttribute;
54 ma->setName( "_value" );
55 ma->setType( dae.getAtomicTypes().get("xsString"));
56 ma->setOffset( daeOffsetOf( domAny , _value ));
57 ma->setContainer( _Meta );
58 _Meta->appendAttribute(ma);
59 }
60
61 _Meta->setElementSize(sizeof(domAny));
62 _Meta->validate();
63
64 return _Meta;
65 }
66
~domAny()67 domAny::~domAny() {
68 // domAny objects own their corresponding daeMetaElement
69 delete _meta;
70 }
71
72 // Implementation of daeMetaAttribute that understands how domAny works
73 class domAnyAttribute : public daeMetaAttribute {
74 public:
getWritableMemory(daeElement * e)75 virtual daeChar* getWritableMemory(daeElement* e) {
76 return (daeChar*)&((domAny*)e)->attrs[_offset];
77 }
78 };
79
setAttribute(daeString attrName,daeString attrValue)80 daeBool domAny::setAttribute(daeString attrName, daeString attrValue) {
81 if (_meta == NULL)
82 return false;
83
84 //if the attribute already exists set it.
85 if (daeElement::setAttribute(attrName, attrValue))
86 return true;
87
88 //else register it and then set it.
89 attrs.append("");
90 daeMetaAttribute *ma = new domAnyAttribute;
91 ma->setName( attrName );
92 ma->setType( getDAE()->getAtomicTypes().get("xsString"));
93 ma->setOffset((daeInt)attrs.getCount()-1);
94 ma->setContainer( _meta );
95 if (ma->getType()) {
96 _meta->appendAttribute(ma);
97 _validAttributeArray.append( true );
98 ma->stringToMemory(this, attrValue);
99 return true;
100 }
101
102 delete ma;
103 return false;
104 }
105
106
107