1 | #include "file.hpp" |
---|
2 | |
---|
3 | #include "attribute_template_impl.hpp" |
---|
4 | #include "object_template_impl.hpp" |
---|
5 | #include "group_template_impl.hpp" |
---|
6 | |
---|
7 | #include "object_factory.hpp" |
---|
8 | #include "object_factory_impl.hpp" |
---|
9 | |
---|
10 | namespace xmlioserver { |
---|
11 | namespace tree { |
---|
12 | |
---|
13 | /// ////////////////////// Définitions ////////////////////// /// |
---|
14 | |
---|
15 | CFile::CFile(void) |
---|
16 | : CObjectTemplate<CFile>(), CFileAttributes() |
---|
17 | , vFieldGroup(), data_out(), enabledFields() |
---|
18 | { /* Ne rien faire de plus */ } |
---|
19 | |
---|
20 | CFile::CFile(const StdString & id) |
---|
21 | : CObjectTemplate<CFile>(id), CFileAttributes() |
---|
22 | , vFieldGroup(), data_out(), enabledFields() |
---|
23 | { /* Ne rien faire de plus */ } |
---|
24 | |
---|
25 | CFile::~CFile(void) |
---|
26 | { /* Ne rien faire de plus */ } |
---|
27 | |
---|
28 | ///--------------------------------------------------------------- |
---|
29 | |
---|
30 | StdString CFile::GetName(void) { return (StdString("file")); } |
---|
31 | StdString CFile::GetDefName(void){ return (CFile::GetName()); } |
---|
32 | ENodeType CFile::GetType(void) { return (eFile); } |
---|
33 | |
---|
34 | //---------------------------------------------------------------- |
---|
35 | |
---|
36 | boost::shared_ptr<io::CDataOutput> CFile::getDataOutput(void) const |
---|
37 | { |
---|
38 | return (data_out); |
---|
39 | } |
---|
40 | |
---|
41 | boost::shared_ptr<CFieldGroup> CFile::getVirtualFieldGroup(void) const |
---|
42 | { |
---|
43 | return (this->vFieldGroup); |
---|
44 | } |
---|
45 | |
---|
46 | std::vector<boost::shared_ptr<CField> > CFile::getAllFields(void) const |
---|
47 | { |
---|
48 | return (this->vFieldGroup->getAllChildren()); |
---|
49 | } |
---|
50 | |
---|
51 | //---------------------------------------------------------------- |
---|
52 | |
---|
53 | std::vector<boost::shared_ptr<CField> > CFile::getEnabledFields |
---|
54 | (int default_outputlevel, int default_level, bool default_enabled) |
---|
55 | { |
---|
56 | if (!this->enabledFields.empty()) |
---|
57 | return (this->enabledFields); |
---|
58 | |
---|
59 | const int _outputlevel = |
---|
60 | (!output_level.isEmpty()) ? output_level.getValue() : default_outputlevel; |
---|
61 | std::vector<boost::shared_ptr<CField> >::iterator it; |
---|
62 | this->enabledFields = this->getAllFields(); |
---|
63 | |
---|
64 | for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) |
---|
65 | { |
---|
66 | if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... |
---|
67 | { |
---|
68 | if (! (*it)->enabled.getValue()) |
---|
69 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
70 | } |
---|
71 | else // Si l'attribut 'enabled' n'est pas défini ... |
---|
72 | { |
---|
73 | if (!default_enabled) |
---|
74 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
75 | } |
---|
76 | |
---|
77 | if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... |
---|
78 | { |
---|
79 | if ((*it)->level.getValue() > _outputlevel) |
---|
80 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
81 | } |
---|
82 | else // Si l'attribut 'level' n'est pas défini ... |
---|
83 | { |
---|
84 | if (default_level > _outputlevel) |
---|
85 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
86 | } |
---|
87 | |
---|
88 | // Le champ est finalement actif, on ajoute la référence au champ de base. |
---|
89 | (*it)->setRelFile(CObjectFactory::GetObject(this)); |
---|
90 | (*it)->baseRefObject->refObject.push_back(*it); |
---|
91 | } |
---|
92 | |
---|
93 | return (this->enabledFields); |
---|
94 | } |
---|
95 | |
---|
96 | //---------------------------------------------------------------- |
---|
97 | |
---|
98 | void CFile::setVirtualFieldGroup(boost::shared_ptr<CFieldGroup> newVFieldGroup) |
---|
99 | { |
---|
100 | this->vFieldGroup = newVFieldGroup; |
---|
101 | } |
---|
102 | |
---|
103 | //---------------------------------------------------------------- |
---|
104 | |
---|
105 | void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId) |
---|
106 | { |
---|
107 | this->setVirtualFieldGroup |
---|
108 | (CObjectFactory::CreateObject<CFieldGroup>(/*newVFieldGroupId*/)); |
---|
109 | } |
---|
110 | |
---|
111 | //---------------------------------------------------------------- |
---|
112 | |
---|
113 | void CFile::initializeDataOutput(boost::shared_ptr<io::CDataOutput> dout) |
---|
114 | { |
---|
115 | this->data_out = dout; |
---|
116 | this->data_out->writeFile(CObjectFactory::GetObject<CFile>(this)); |
---|
117 | |
---|
118 | std::vector<boost::shared_ptr<CField> >::iterator it, end = this->enabledFields.end(); |
---|
119 | |
---|
120 | for (it = this->enabledFields.begin() ;it != end; it++) |
---|
121 | { |
---|
122 | boost::shared_ptr<CField> field = *it; |
---|
123 | this->data_out->writeFieldGrid(field); |
---|
124 | } |
---|
125 | |
---|
126 | for (it = this->enabledFields.begin() ;it != end; it++) |
---|
127 | { |
---|
128 | boost::shared_ptr<CField> field = *it; |
---|
129 | this->data_out->writeField(field); |
---|
130 | } |
---|
131 | |
---|
132 | this->data_out->definition_end(); |
---|
133 | } |
---|
134 | |
---|
135 | //---------------------------------------------------------------- |
---|
136 | |
---|
137 | void CFile::parse(xml::CXMLNode & node) |
---|
138 | { |
---|
139 | SuperClass::parse(node); |
---|
140 | if (node.goToChildElement() & this->hasId()) |
---|
141 | { // Si la définition du fichier intégre des champs et si le fichier est identifié. |
---|
142 | node.goToParentElement(); |
---|
143 | this->setVirtualFieldGroup(this->getId()); |
---|
144 | this->getVirtualFieldGroup()->parse(node, false); |
---|
145 | } |
---|
146 | } |
---|
147 | //---------------------------------------------------------------- |
---|
148 | |
---|
149 | StdString CFile::toString(void) const |
---|
150 | { |
---|
151 | StdOStringStream oss; |
---|
152 | |
---|
153 | oss << "<" << CFile::GetName() << " "; |
---|
154 | if (this->hasId()) |
---|
155 | oss << " id=\"" << this->getId() << "\" "; |
---|
156 | oss << SuperClassAttribute::toString() << ">" << std::endl; |
---|
157 | if (this->getVirtualFieldGroup().get() != NULL) |
---|
158 | oss << *this->getVirtualFieldGroup() << std::endl; |
---|
159 | oss << "</" << CFile::GetName() << " >"; |
---|
160 | return (oss.str()); |
---|
161 | } |
---|
162 | |
---|
163 | //---------------------------------------------------------------- |
---|
164 | |
---|
165 | void CFile::solveDescInheritance(const CAttributeMap * const parent) |
---|
166 | { |
---|
167 | SuperClassAttribute::setAttributes(parent); |
---|
168 | this->getVirtualFieldGroup()->solveDescInheritance(NULL); |
---|
169 | } |
---|
170 | |
---|
171 | //---------------------------------------------------------------- |
---|
172 | |
---|
173 | void CFile::solveFieldRefInheritance(void) |
---|
174 | { |
---|
175 | // Résolution des héritages par référence de chacun des champs contenus dans le fichier. |
---|
176 | std::vector<boost::shared_ptr<CField> > allF = this->getAllFields(); |
---|
177 | for (unsigned int i = 0; i < allF.size(); i++) |
---|
178 | allF[i]->solveRefInheritance(); |
---|
179 | } |
---|
180 | |
---|
181 | //---------------------------------------------------------------- |
---|
182 | |
---|
183 | void CFile::solveEFGridRef(void) |
---|
184 | { |
---|
185 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
186 | this->enabledFields[i]->solveGridReference(); |
---|
187 | } |
---|
188 | |
---|
189 | //---------------------------------------------------------------- |
---|
190 | |
---|
191 | void CFile::solveEFOperation(void) |
---|
192 | { |
---|
193 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
194 | this->enabledFields[i]->solveOperation(); |
---|
195 | } |
---|
196 | |
---|
197 | //--------------------------------------------------------------- |
---|
198 | |
---|
199 | void CFile::toBinary (StdOStream & os) const |
---|
200 | { |
---|
201 | ENodeType genum = CFileGroup::GetType(); |
---|
202 | bool hasVFG = (this->getVirtualFieldGroup().get() != NULL); |
---|
203 | SuperClass::toBinary(os); |
---|
204 | |
---|
205 | os.write (reinterpret_cast<const char*>(&genum) , sizeof(ENodeType)); |
---|
206 | os.write (reinterpret_cast<const char*>(&hasVFG) , sizeof(bool)); |
---|
207 | |
---|
208 | if (hasVFG)this->getVirtualFieldGroup()->toBinary(os); |
---|
209 | |
---|
210 | } |
---|
211 | |
---|
212 | //---------------------------------------------------------------- |
---|
213 | |
---|
214 | void CFile::fromBinary(StdIStream & is) |
---|
215 | { |
---|
216 | ENodeType renum = Unknown; |
---|
217 | bool hasVFG = false; |
---|
218 | SuperClass::fromBinary(is); |
---|
219 | |
---|
220 | is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType)); |
---|
221 | is.read (reinterpret_cast<char*>(&hasVFG), sizeof(bool)); |
---|
222 | |
---|
223 | if (renum != CFileGroup::GetType()) |
---|
224 | ERROR("CFile::fromBinary(StdIStream & is)", |
---|
225 | << "[ renum = " << renum << "] Bad type !"); |
---|
226 | |
---|
227 | this->setVirtualFieldGroup(this->getId()); |
---|
228 | if (hasVFG)this->getVirtualFieldGroup()->fromBinary(is); |
---|
229 | |
---|
230 | } |
---|
231 | |
---|
232 | ///--------------------------------------------------------------- |
---|
233 | |
---|
234 | } // namespace tree |
---|
235 | } // namespace xmlioserver |
---|