1 | #ifndef __FILE_GROUP__ |
---|
2 | #define __FILE_GROUP__ |
---|
3 | |
---|
4 | namespace XMLIOSERVER |
---|
5 | { |
---|
6 | class FileGroup : public GroupTemplate<CFile, FileAttribut> |
---|
7 | { |
---|
8 | public: |
---|
9 | |
---|
10 | FileGroup(void) : GroupTemplate<CFile, FileAttribut>() |
---|
11 | {/* Ne rien faire de plus */} |
---|
12 | FileGroup(const string& _id) : GroupTemplate<CFile, FileAttribut>(_id) |
---|
13 | {/* Ne rien faire de plus */} |
---|
14 | |
---|
15 | const char* getName(void) const {return ("File_Group"); } |
---|
16 | |
---|
17 | |
---|
18 | /// TODO A remonter dans l'arbre des héritages |
---|
19 | friend ostream& operator<< (ostream& out, const FileGroup& c) |
---|
20 | { |
---|
21 | const AttributRegistrar &ar = c; |
---|
22 | out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl; |
---|
23 | |
---|
24 | // Ecriture des sous-groupes. |
---|
25 | for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) |
---|
26 | out << *((FileGroup*)c.groupList.getVector()[i]) << std::endl; |
---|
27 | |
---|
28 | // Ecriture des enfants. |
---|
29 | for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) |
---|
30 | out << *((CFile*)c.childList.getVector()[i]) << std::endl; |
---|
31 | |
---|
32 | out << NIndent << "</" << c.getName()<< ">" << DecEndl; |
---|
33 | |
---|
34 | return (out); |
---|
35 | } |
---|
36 | |
---|
37 | /// TODO A remonter dans l'arbre des héritages |
---|
38 | void resolveDescInheritance(const AttributRegistrar* _parent = 0) |
---|
39 | { |
---|
40 | const vector<CFile*>& childvect = childList.getVector(); |
---|
41 | const vector<GroupTemplate<CFile, FileAttribut>*>& groupvect = groupList.getVector(); |
---|
42 | |
---|
43 | // On complÚte les propres attributs du groupe. |
---|
44 | if (_parent!= NULL) addAttributes(*_parent); |
---|
45 | |
---|
46 | for(unsigned int i = 0; i < childvect.size() ; i++) |
---|
47 | { // on complÚte les attributs des champs enfants. |
---|
48 | childvect[i] -> addAttributes(*this); |
---|
49 | if (childvect[i]->hasVirtualFieldGroup()) |
---|
50 | childvect[i]->getVirtualFieldGroup()-> resolveDescInheritance(); |
---|
51 | } |
---|
52 | |
---|
53 | for(unsigned int i = 0; i < groupvect.size() ; i++) |
---|
54 | // on complÚte les attributs des groupes de champs enfants. |
---|
55 | ((FileGroup*)groupvect[i]) -> resolveDescInheritance(this); |
---|
56 | } |
---|
57 | |
---|
58 | void parse (XMLNode& _node) |
---|
59 | { |
---|
60 | string name = _node.getElementName(); |
---|
61 | THashAttributes attributes; |
---|
62 | |
---|
63 | /// PARSING GESTION DES ATTRIBUTS /// |
---|
64 | _node.getAttributes(attributes); |
---|
65 | this->setAttributes(attributes); |
---|
66 | |
---|
67 | if (attributes.end() != attributes.find("src")) |
---|
68 | { // Si une demande d'inclusion de fichier est trouvé. |
---|
69 | XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); |
---|
70 | parse (_node_inc); |
---|
71 | } |
---|
72 | |
---|
73 | attributes.clear(); |
---|
74 | |
---|
75 | /// PARSING POUR GESION DES ENFANTS |
---|
76 | if (!(_node.goToChildElement())) |
---|
77 | WARNING("Le groupe de fichier ne contient pas d'enfant !"); |
---|
78 | else |
---|
79 | { |
---|
80 | ////////////////////////////////////// |
---|
81 | do { // Parcours des contexts pour traitement. |
---|
82 | |
---|
83 | string name = _node.getElementName(); |
---|
84 | attributes.clear(); |
---|
85 | _node.getAttributes(attributes); |
---|
86 | |
---|
87 | if (name.compare("file_group") == 0) |
---|
88 | { // Parsing pour les groupes de champs |
---|
89 | |
---|
90 | FileGroup* fgroup = NULL; |
---|
91 | |
---|
92 | if (attributes.end() != attributes.find("id")) |
---|
93 | {// Si l'identifiant est défini. |
---|
94 | if (FileGroup::HasObject(attributes["id"])) |
---|
95 | WARNING("Dans le context actuel, un groupe de fichier du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO |
---|
96 | fgroup = (FileGroup*)(&createGroup(attributes["id"])); |
---|
97 | fgroup->parse(_node); |
---|
98 | } |
---|
99 | else |
---|
100 | {// Si l'identifiant n'est pas défini. |
---|
101 | fgroup = (FileGroup*)(&createGroup()); |
---|
102 | fgroup->parse(_node); |
---|
103 | } |
---|
104 | continue; |
---|
105 | |
---|
106 | } |
---|
107 | else if (name.compare("file") == 0) |
---|
108 | { // Parsing pour les champs. |
---|
109 | |
---|
110 | CFile* file = NULL; |
---|
111 | |
---|
112 | if (attributes.end() != attributes.find("id")) |
---|
113 | {// Si l'identifiant est défini. |
---|
114 | if (CFile::HasObject(attributes["id"])) |
---|
115 | WARNING("Dans le context actuel, un fichier du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO |
---|
116 | file = (CFile*)(&createChild(attributes["id"])); |
---|
117 | file->parse(_node); |
---|
118 | } |
---|
119 | else |
---|
120 | {// Si l'identifiant n'est pas défini. |
---|
121 | file = (CFile*)(&createChild()); |
---|
122 | file->parse(_node); |
---|
123 | } |
---|
124 | continue; |
---|
125 | } |
---|
126 | else |
---|
127 | WARNING("Un groupe de fichiers ne peut contenir qu'un fichier ou un autre groupe de fichiers !"); |
---|
128 | |
---|
129 | } while (_node.goToNextElement()); |
---|
130 | ////////////////////////////////////// |
---|
131 | _node.goToParentElement(); // Retour au parent |
---|
132 | } |
---|
133 | |
---|
134 | return; |
---|
135 | } |
---|
136 | |
---|
137 | virtual ~FileGroup(void) |
---|
138 | {/* Ne rien faire de plus */ } |
---|
139 | |
---|
140 | }; // class FileGroup |
---|
141 | |
---|
142 | typedef FileGroup FileDefinition ; |
---|
143 | |
---|
144 | }; // namespace XMLIOSERVER |
---|
145 | |
---|
146 | #endif // __FILE_GROUP__ |
---|
147 | |
---|