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 | { |
---|
12 | namespace tree |
---|
13 | { |
---|
14 | /// ////////////////////// Définitions ////////////////////// /// |
---|
15 | |
---|
16 | CFile::CFile(void) |
---|
17 | : CObjectTemplate<CFile>(), CFileAttributes() |
---|
18 | , vFieldGroup(), data_out(), enabledFields() |
---|
19 | { /* Ne rien faire de plus */ } |
---|
20 | |
---|
21 | CFile::CFile(const StdString & id) |
---|
22 | : CObjectTemplate<CFile>(id), CFileAttributes() |
---|
23 | , vFieldGroup(), data_out(), enabledFields() |
---|
24 | { /* Ne rien faire de plus */ } |
---|
25 | |
---|
26 | CFile::~CFile(void) |
---|
27 | { /* Ne rien faire de plus */ } |
---|
28 | |
---|
29 | ///--------------------------------------------------------------- |
---|
30 | |
---|
31 | StdString CFile::GetName(void) { return (StdString("file")); } |
---|
32 | StdString CFile::GetDefName(void){ return (CFile::GetName()); } |
---|
33 | |
---|
34 | boost::shared_ptr<CFieldGroup> CFile::getVirtualFieldGroup(void) const |
---|
35 | { |
---|
36 | return (this->vFieldGroup); |
---|
37 | } |
---|
38 | |
---|
39 | std::vector<boost::shared_ptr<CField> > CFile::getAllFields(void) const |
---|
40 | { |
---|
41 | return (this->vFieldGroup->getAllChildren()); |
---|
42 | } |
---|
43 | |
---|
44 | //---------------------------------------------------------------- |
---|
45 | |
---|
46 | std::vector<boost::shared_ptr<CField> > CFile::getEnabledFields |
---|
47 | (int default_outputlevel, int default_level, bool default_enabled) |
---|
48 | { |
---|
49 | if (!this->enabledFields.empty()) |
---|
50 | return (this->enabledFields); |
---|
51 | |
---|
52 | const int _outputlevel = |
---|
53 | (!output_level.isEmpty()) ? output_level.getValue() : default_outputlevel; |
---|
54 | std::vector<boost::shared_ptr<CField> >::iterator it; |
---|
55 | this->enabledFields = this->getAllFields(); |
---|
56 | |
---|
57 | for ( it = this->enabledFields.begin() ; it != this->enabledFields.end(); it++ ) |
---|
58 | { |
---|
59 | if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... |
---|
60 | { |
---|
61 | if (! (*it)->enabled.getValue()) |
---|
62 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
63 | } |
---|
64 | else // Si l'attribut 'enabled' n'est pas défini ... |
---|
65 | { |
---|
66 | if (!default_enabled) |
---|
67 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
68 | } |
---|
69 | |
---|
70 | if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... |
---|
71 | { |
---|
72 | if ((*it)->level.getValue() > _outputlevel) |
---|
73 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
74 | } |
---|
75 | else // Si l'attribut 'level' n'est pas défini ... |
---|
76 | { |
---|
77 | if (default_level > _outputlevel) |
---|
78 | { it--; this->enabledFields.erase(it+1); continue; } |
---|
79 | } |
---|
80 | |
---|
81 | // Le champ est finalement actif, on ajoute la référence au champ de base. |
---|
82 | (*it)->setRelFile(CObjectFactory::GetObject(this)); |
---|
83 | (*it)->baseRefObject->refObject.push_back(*it); |
---|
84 | } |
---|
85 | |
---|
86 | return (this->enabledFields); |
---|
87 | } |
---|
88 | |
---|
89 | //---------------------------------------------------------------- |
---|
90 | |
---|
91 | void CFile::setVirtualFieldGroup(boost::shared_ptr<CFieldGroup> newVFieldGroup) |
---|
92 | { this->vFieldGroup = newVFieldGroup; } |
---|
93 | |
---|
94 | void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId) |
---|
95 | { |
---|
96 | this->setVirtualFieldGroup |
---|
97 | (CObjectFactory::CreateObject<CFieldGroup>(newVFieldGroupId)); |
---|
98 | } |
---|
99 | |
---|
100 | void CFile::initializeDataOutput(boost::shared_ptr<io::CDataOutput> dout) |
---|
101 | { |
---|
102 | this->data_out = dout; |
---|
103 | this->data_out->writeFile(CObjectFactory::GetObject<CFile>(this)); |
---|
104 | BOOST_FOREACH(boost::shared_ptr<CField> field, enabledFields) |
---|
105 | this->data_out->writeFieldGrid(field); |
---|
106 | BOOST_FOREACH(boost::shared_ptr<CField> field, enabledFields) |
---|
107 | this->data_out->writeField(field); |
---|
108 | this->data_out->definition_end(); |
---|
109 | } |
---|
110 | |
---|
111 | void CFile::parse(xml::CXMLNode & node) |
---|
112 | { |
---|
113 | SuperClass::parse(node); |
---|
114 | if (node.goToChildElement() & this->hasId()) |
---|
115 | { // Si la définition du fichier intégre des champs et si le fichier est identifié. |
---|
116 | node.goToParentElement(); |
---|
117 | this->setVirtualFieldGroup(this->getId()); |
---|
118 | this->getVirtualFieldGroup()->parse(node, false); |
---|
119 | } |
---|
120 | } |
---|
121 | //---------------------------------------------------------------- |
---|
122 | |
---|
123 | StdString CFile::toString(void) const |
---|
124 | { |
---|
125 | StdOStringStream oss; |
---|
126 | |
---|
127 | oss << "< " << CFile::GetName() << " "; |
---|
128 | if (this->hasId()) |
---|
129 | oss << " id=\"" << this->getId() << "\" "; |
---|
130 | oss << SuperClassAttribute::toString() << ">" << std::endl; |
---|
131 | if (this->getVirtualFieldGroup().get() != NULL) |
---|
132 | oss << *this->getVirtualFieldGroup() << std::endl; |
---|
133 | oss << "</ " << CFile::GetName() << " >"; |
---|
134 | return (oss.str()); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | void CFile::solveDescInheritance(const CAttributeMap * const parent) |
---|
139 | { |
---|
140 | SuperClassAttribute::setAttributes(parent); |
---|
141 | this->getVirtualFieldGroup()->solveDescInheritance(NULL); |
---|
142 | } |
---|
143 | |
---|
144 | void CFile::solveFieldRefInheritance(void) |
---|
145 | { |
---|
146 | // Résolution des héritages par référence de chacun des champs contenus dans le fichier. |
---|
147 | std::vector<boost::shared_ptr<CField> > allF = this->getAllFields(); |
---|
148 | for (unsigned int i = 0; i < allF.size(); i++) |
---|
149 | allF[i]->solveRefInheritance(); |
---|
150 | } |
---|
151 | |
---|
152 | void CFile::solveEFGridRef(void) |
---|
153 | { |
---|
154 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
155 | this->enabledFields[i]->solveGridReference(); |
---|
156 | } |
---|
157 | |
---|
158 | void CFile::solveEFOperation(void) |
---|
159 | { |
---|
160 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
161 | this->enabledFields[i]->solveOperation(); |
---|
162 | } |
---|
163 | |
---|
164 | ///--------------------------------------------------------------- |
---|
165 | } // namespace tree |
---|
166 | } // namespace xmlioserver |
---|