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