[152] | 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 | |
---|
[168] | 10 | namespace xmlioserver { |
---|
| 11 | namespace tree { |
---|
| 12 | |
---|
| 13 | /// ////////////////////// Définitions ////////////////////// /// |
---|
[152] | 14 | |
---|
[168] | 15 | CFile::CFile(void) |
---|
| 16 | : CObjectTemplate<CFile>(), CFileAttributes() |
---|
| 17 | , vFieldGroup(), data_out(), enabledFields() |
---|
| 18 | { /* Ne rien faire de plus */ } |
---|
[152] | 19 | |
---|
[168] | 20 | CFile::CFile(const StdString & id) |
---|
| 21 | : CObjectTemplate<CFile>(id), CFileAttributes() |
---|
| 22 | , vFieldGroup(), data_out(), enabledFields() |
---|
| 23 | { /* Ne rien faire de plus */ } |
---|
[152] | 24 | |
---|
[168] | 25 | CFile::~CFile(void) |
---|
| 26 | { /* Ne rien faire de plus */ } |
---|
[152] | 27 | |
---|
[168] | 28 | ///--------------------------------------------------------------- |
---|
[152] | 29 | |
---|
[168] | 30 | StdString CFile::GetName(void) { return (StdString("file")); } |
---|
| 31 | StdString CFile::GetDefName(void){ return (CFile::GetName()); } |
---|
| 32 | ENodeType CFile::GetType(void) { return (eFile); } |
---|
[152] | 33 | |
---|
[168] | 34 | //---------------------------------------------------------------- |
---|
[152] | 35 | |
---|
[214] | 36 | boost::shared_ptr<io::CDataOutput> CFile::getDataOutput(void) const |
---|
| 37 | { |
---|
| 38 | return (data_out); |
---|
| 39 | } |
---|
| 40 | |
---|
[168] | 41 | boost::shared_ptr<CFieldGroup> CFile::getVirtualFieldGroup(void) const |
---|
| 42 | { |
---|
| 43 | return (this->vFieldGroup); |
---|
| 44 | } |
---|
[152] | 45 | |
---|
[168] | 46 | std::vector<boost::shared_ptr<CField> > CFile::getAllFields(void) const |
---|
| 47 | { |
---|
| 48 | return (this->vFieldGroup->getAllChildren()); |
---|
| 49 | } |
---|
[152] | 50 | |
---|
[168] | 51 | //---------------------------------------------------------------- |
---|
[152] | 52 | |
---|
[168] | 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); |
---|
[152] | 58 | |
---|
[168] | 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 ... |
---|
[152] | 67 | { |
---|
[168] | 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 | } |
---|
[152] | 76 | |
---|
[168] | 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; } |
---|
[152] | 81 | } |
---|
[168] | 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 | } |
---|
[152] | 87 | |
---|
[168] | 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); |
---|
[152] | 91 | } |
---|
| 92 | |
---|
[168] | 93 | return (this->enabledFields); |
---|
| 94 | } |
---|
[152] | 95 | |
---|
[168] | 96 | //---------------------------------------------------------------- |
---|
[152] | 97 | |
---|
[168] | 98 | void CFile::setVirtualFieldGroup(boost::shared_ptr<CFieldGroup> newVFieldGroup) |
---|
[189] | 99 | { |
---|
| 100 | this->vFieldGroup = newVFieldGroup; |
---|
| 101 | } |
---|
[168] | 102 | |
---|
[188] | 103 | //---------------------------------------------------------------- |
---|
| 104 | |
---|
[168] | 105 | void CFile::setVirtualFieldGroup(const StdString & newVFieldGroupId) |
---|
| 106 | { |
---|
| 107 | this->setVirtualFieldGroup |
---|
[265] | 108 | (CObjectFactory::CreateObject<CFieldGroup>(/*newVFieldGroupId*/)); |
---|
[168] | 109 | } |
---|
| 110 | |
---|
[188] | 111 | //---------------------------------------------------------------- |
---|
| 112 | |
---|
[168] | 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++) |
---|
[152] | 121 | { |
---|
[168] | 122 | boost::shared_ptr<CField> field = *it; |
---|
| 123 | this->data_out->writeFieldGrid(field); |
---|
[152] | 124 | } |
---|
[168] | 125 | |
---|
| 126 | for (it = this->enabledFields.begin() ;it != end; it++) |
---|
[152] | 127 | { |
---|
[168] | 128 | boost::shared_ptr<CField> field = *it; |
---|
| 129 | this->data_out->writeField(field); |
---|
| 130 | } |
---|
[152] | 131 | |
---|
[168] | 132 | this->data_out->definition_end(); |
---|
| 133 | } |
---|
[152] | 134 | |
---|
[188] | 135 | //---------------------------------------------------------------- |
---|
| 136 | |
---|
[168] | 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); |
---|
[152] | 145 | } |
---|
[168] | 146 | } |
---|
| 147 | //---------------------------------------------------------------- |
---|
[152] | 148 | |
---|
[168] | 149 | StdString CFile::toString(void) const |
---|
| 150 | { |
---|
| 151 | StdOStringStream oss; |
---|
[152] | 152 | |
---|
[173] | 153 | oss << "<" << CFile::GetName() << " "; |
---|
[168] | 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; |
---|
[173] | 159 | oss << "</" << CFile::GetName() << " >"; |
---|
[168] | 160 | return (oss.str()); |
---|
| 161 | } |
---|
[152] | 162 | |
---|
[188] | 163 | //---------------------------------------------------------------- |
---|
| 164 | |
---|
[168] | 165 | void CFile::solveDescInheritance(const CAttributeMap * const parent) |
---|
| 166 | { |
---|
| 167 | SuperClassAttribute::setAttributes(parent); |
---|
| 168 | this->getVirtualFieldGroup()->solveDescInheritance(NULL); |
---|
| 169 | } |
---|
[152] | 170 | |
---|
[188] | 171 | //---------------------------------------------------------------- |
---|
| 172 | |
---|
[168] | 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 | } |
---|
[152] | 180 | |
---|
[188] | 181 | //---------------------------------------------------------------- |
---|
| 182 | |
---|
[168] | 183 | void CFile::solveEFGridRef(void) |
---|
| 184 | { |
---|
| 185 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
| 186 | this->enabledFields[i]->solveGridReference(); |
---|
| 187 | } |
---|
[152] | 188 | |
---|
[188] | 189 | //---------------------------------------------------------------- |
---|
| 190 | |
---|
[168] | 191 | void CFile::solveEFOperation(void) |
---|
| 192 | { |
---|
| 193 | for (unsigned int i = 0; i < this->enabledFields.size(); i++) |
---|
| 194 | this->enabledFields[i]->solveOperation(); |
---|
| 195 | } |
---|
[174] | 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 | |
---|
[188] | 212 | //---------------------------------------------------------------- |
---|
| 213 | |
---|
[174] | 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 | } |
---|
[152] | 231 | |
---|
[168] | 232 | ///--------------------------------------------------------------- |
---|
[152] | 233 | |
---|
[168] | 234 | } // namespace tree |
---|
[152] | 235 | } // namespace xmlioserver |
---|