[219] | 1 | #include "attribute_map.hpp" |
---|
[313] | 2 | #include "indent.hpp" |
---|
[219] | 3 | |
---|
[335] | 4 | namespace xios |
---|
[219] | 5 | { |
---|
| 6 | /// ////////////////////// Définitions ////////////////////// /// |
---|
[581] | 7 | CAttributeMap* CAttributeMap::Current = NULL; |
---|
[219] | 8 | |
---|
| 9 | CAttributeMap::CAttributeMap(void) |
---|
| 10 | : xios_map<StdString, CAttribute*>() |
---|
| 11 | { CAttributeMap::Current = this; } |
---|
| 12 | |
---|
| 13 | CAttributeMap::~CAttributeMap(void) |
---|
| 14 | { /* Ne rien faire de plus */ } |
---|
[509] | 15 | |
---|
[219] | 16 | ///-------------------------------------------------------------- |
---|
| 17 | |
---|
[1105] | 18 | /*! |
---|
| 19 | Clear all attributes of an object and reset them to empty state |
---|
| 20 | */ |
---|
[219] | 21 | void CAttributeMap::clearAllAttributes(void) |
---|
| 22 | { |
---|
| 23 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
| 24 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
| 25 | for (; it != end; it++) |
---|
| 26 | { |
---|
[581] | 27 | const StdStrAttPair& att = *it; |
---|
[369] | 28 | att.second->reset(); |
---|
[219] | 29 | } |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | //--------------------------------------------------------------- |
---|
| 33 | |
---|
[1105] | 34 | /* |
---|
| 35 | Clear an attribute and reset its value |
---|
| 36 | \param[in] key id of attribute |
---|
| 37 | */ |
---|
[509] | 38 | void CAttributeMap::clearAttribute(const StdString& key) |
---|
| 39 | { |
---|
| 40 | if (hasAttribute(key)) this->find(key)->second->reset(); |
---|
| 41 | } |
---|
| 42 | |
---|
[219] | 43 | //--------------------------------------------------------------- |
---|
[509] | 44 | |
---|
[1105] | 45 | /*! |
---|
| 46 | Set an attribute of certain id with a value |
---|
| 47 | \param[in] key id of the attribute |
---|
| 48 | \param[in] attr value of attribute |
---|
| 49 | */ |
---|
[581] | 50 | void CAttributeMap::setAttribute(const StdString& key, CAttribute* const attr) |
---|
[219] | 51 | { |
---|
| 52 | if (!this->hasAttribute(key)) |
---|
| 53 | ERROR("CAttributeMap::setAttribute(key, attr)", |
---|
| 54 | << "[ key = " << key << "] key not found !"); |
---|
| 55 | if (attr == NULL) |
---|
| 56 | ERROR("CAttributeMap::setAttribute(key, attr)", |
---|
| 57 | << "[ key = " << key << "] attr is null !"); |
---|
[581] | 58 | this->find(key)->second->set(*attr); |
---|
| 59 | // this->find(key)->second->setAnyValue(attr->getAnyValue()); |
---|
[219] | 60 | } |
---|
[509] | 61 | |
---|
[219] | 62 | //--------------------------------------------------------------- |
---|
[509] | 63 | |
---|
[1105] | 64 | /*! |
---|
| 65 | Subscript operator. Return attribute with a specific id |
---|
| 66 | */ |
---|
[581] | 67 | CAttribute* CAttributeMap::operator[](const StdString& key) |
---|
[219] | 68 | { |
---|
| 69 | if (!this->hasAttribute(key)) |
---|
[581] | 70 | ERROR("CAttributeMap::operator[](const StdString& key)", |
---|
[219] | 71 | << "[ key = " << key << "] key not found !"); |
---|
[581] | 72 | return SuperClassMap::operator[](key); |
---|
[219] | 73 | } |
---|
[509] | 74 | |
---|
[219] | 75 | //--------------------------------------------------------------- |
---|
[509] | 76 | |
---|
[219] | 77 | StdString CAttributeMap::toString(void) const |
---|
| 78 | { |
---|
| 79 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
| 80 | StdOStringStream oss; |
---|
[509] | 81 | |
---|
[219] | 82 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
| 83 | for (; it != end; it++) |
---|
| 84 | { |
---|
[581] | 85 | const StdStrAttPair& att = *it; |
---|
[219] | 86 | if (!att.second->isEmpty()) |
---|
| 87 | oss << *att.second << " "; |
---|
| 88 | } |
---|
[581] | 89 | return oss.str(); |
---|
[219] | 90 | } |
---|
[509] | 91 | |
---|
[219] | 92 | //--------------------------------------------------------------- |
---|
[509] | 93 | |
---|
[581] | 94 | void CAttributeMap::fromString(const StdString& str) |
---|
[509] | 95 | { |
---|
[581] | 96 | ERROR("CAttributeMap::fromString(const StdString& str)", |
---|
[509] | 97 | << "[ str = " << str << "] Not implemented yet !"); |
---|
[219] | 98 | } |
---|
[509] | 99 | |
---|
[219] | 100 | //--------------------------------------------------------------- |
---|
| 101 | |
---|
[581] | 102 | //StdOStream& operator << (StdOStream& os, const CAttributeMap& attributmap) |
---|
[219] | 103 | //{ os << attributmap.toString(); return (os); } |
---|
[509] | 104 | |
---|
[219] | 105 | //--------------------------------------------------------------- |
---|
[509] | 106 | |
---|
[581] | 107 | void CAttributeMap::setAttributes(const xml::THashAttributes& attributes) |
---|
[219] | 108 | { |
---|
| 109 | for (xml::THashAttributes::const_iterator it = attributes.begin(); |
---|
| 110 | it != attributes.end(); |
---|
[581] | 111 | it++) |
---|
[278] | 112 | { |
---|
[581] | 113 | if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src")) != 0) |
---|
[219] | 114 | { |
---|
| 115 | //if (CAttributeMap::operator[]((*it).first)->isEmpty()) |
---|
| 116 | CAttributeMap::operator[]((*it).first)->fromString((*it).second); |
---|
| 117 | } |
---|
[278] | 118 | } |
---|
[219] | 119 | } |
---|
[509] | 120 | |
---|
[1105] | 121 | /*! |
---|
| 122 | Compare two attribute maps |
---|
| 123 | \param [in] another attribute map to compare |
---|
[1117] | 124 | \param [in] excludedAttrs attribute to be excluded from comparasion |
---|
[1105] | 125 | \return true if these two maps have same attributes whose value are identical |
---|
| 126 | */ |
---|
[1117] | 127 | bool CAttributeMap::isEqual(const CAttributeMap& another, const vector<StdString>& excludedAttrs) |
---|
[1105] | 128 | { |
---|
| 129 | SuperClassMap::const_iterator itb = another.begin(), ite = another.end(), it; |
---|
| 130 | for (it = itb; it !=ite; ++it) |
---|
| 131 | { |
---|
[1117] | 132 | bool excluded = false; |
---|
| 133 | for (int idx = 0; idx < excludedAttrs.size(); ++idx) |
---|
[1105] | 134 | { |
---|
[1117] | 135 | if (0 == (*it).first.compare(excludedAttrs[idx])) |
---|
| 136 | { |
---|
| 137 | excluded = true; |
---|
| 138 | break; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | if (!excluded) |
---|
| 143 | { |
---|
| 144 | if ((*it).first.compare(StdString("id")) != 0 && (*it).first.compare(StdString("src")) != 0) |
---|
| 145 | { |
---|
| 146 | if (this->hasAttribute(it->first)) |
---|
| 147 | { |
---|
| 148 | if (!((*it).second->isEqual(*(*this)[it->first]))) |
---|
| 149 | { |
---|
| 150 | return false; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | else |
---|
| 154 | return false; |
---|
[1105] | 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | return true; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
[219] | 163 | //--------------------------------------------------------------- |
---|
[509] | 164 | |
---|
| 165 | /*! |
---|
| 166 | \brief Set attributes from a specific attributemap, considered parent. |
---|
| 167 | The child attribute map will insert the attributes of its parent into its current attribute map. |
---|
| 168 | The existing attributes can be filled with the values of the parent map if they are empty or |
---|
| 169 | simply replaced by these values depending on choice of user. |
---|
| 170 | \param [in] _parent Attribute map from which the current map gets attributes. |
---|
| 171 | \param [in] apply Specify if current attribute map is replaced by the attributes of parent (false) |
---|
| 172 | or filled in in case of emptyp (true) |
---|
| 173 | */ |
---|
[581] | 174 | void CAttributeMap::setAttributes(const CAttributeMap* const _parent, bool apply) |
---|
[219] | 175 | { |
---|
| 176 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
[509] | 177 | |
---|
[219] | 178 | SuperClassMap::const_iterator it = _parent->begin(), end = _parent->end(); |
---|
| 179 | for (; it != end; it++) |
---|
| 180 | { |
---|
[581] | 181 | const StdStrAttPair& el = *it; |
---|
[219] | 182 | if (this->hasAttribute(el.first)) |
---|
| 183 | { |
---|
[581] | 184 | CAttribute* currentAtt = CAttributeMap::operator[](el.first); |
---|
| 185 | CAttribute* parentAtt = el.second; |
---|
[445] | 186 | if (apply) |
---|
[219] | 187 | { |
---|
[1112] | 188 | if (currentAtt->isEmpty() && currentAtt->canInherite() && !el.second->isEmpty()) |
---|
[445] | 189 | { |
---|
| 190 | this->setAttribute(el.first, el.second); |
---|
| 191 | } |
---|
[219] | 192 | } |
---|
[581] | 193 | else currentAtt->setInheritedValue(*parentAtt); |
---|
[219] | 194 | } |
---|
| 195 | } |
---|
| 196 | } |
---|
[509] | 197 | |
---|
[1105] | 198 | /*! |
---|
| 199 | Duplicate attribute map with a specific attribute map. |
---|
| 200 | Copy all non-empty attribute of the current attribute map |
---|
| 201 | \param [in] srcAttr attribute map which is copied from. |
---|
| 202 | */ |
---|
[623] | 203 | void CAttributeMap::duplicateAttributes(const CAttributeMap* const srcAttr) |
---|
| 204 | { |
---|
| 205 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
| 206 | |
---|
| 207 | SuperClassMap::const_iterator it = srcAttr->begin(), end = srcAttr->end(); |
---|
| 208 | for (; it != end; it++) |
---|
| 209 | { |
---|
| 210 | const StdStrAttPair& el = *it; |
---|
| 211 | if (this->hasAttribute(el.first)) |
---|
| 212 | { |
---|
| 213 | if (!el.second->isEmpty()) |
---|
| 214 | { |
---|
| 215 | this->setAttribute(el.first, el.second); |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | |
---|
[219] | 221 | //--------------------------------------------------------------- |
---|
[509] | 222 | /* |
---|
[581] | 223 | void CAttributeMap::toBinary(StdOStream& os) const |
---|
[219] | 224 | { |
---|
| 225 | typedef std::pair<StdString, CAttribute*> StdStrAttPair; |
---|
| 226 | SuperClassMap::const_iterator it = this->begin(), end = this->end(); |
---|
[509] | 227 | |
---|
[219] | 228 | const StdSize nbatt = SuperClassMap::size(); |
---|
| 229 | os.write (reinterpret_cast<const char*>(&nbatt) , sizeof(StdSize)); |
---|
[509] | 230 | |
---|
[219] | 231 | for (; it != end; it++) |
---|
| 232 | { |
---|
[581] | 233 | const StdString& key = it->first; |
---|
[509] | 234 | const CAttribute* value = it->second; |
---|
[219] | 235 | const StdSize size = key.size(); |
---|
[509] | 236 | |
---|
[219] | 237 | os.write (reinterpret_cast<const char*>(&size) , sizeof(StdSize)); |
---|
[581] | 238 | os.write (key.data(), size* sizeof(char)); |
---|
[509] | 239 | |
---|
[219] | 240 | if (!value->isEmpty()) |
---|
| 241 | { |
---|
| 242 | bool b = true; |
---|
| 243 | os.write (reinterpret_cast<const char*>(&b) , sizeof(bool)); |
---|
| 244 | value->toBinary(os); |
---|
| 245 | } |
---|
[509] | 246 | else |
---|
[219] | 247 | { |
---|
| 248 | bool b = false; |
---|
| 249 | os.write (reinterpret_cast<const char*>(&b) , sizeof(bool)); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | } |
---|
[509] | 253 | |
---|
[219] | 254 | //--------------------------------------------------------------- |
---|
[509] | 255 | |
---|
[581] | 256 | void CAttributeMap::fromBinary(StdIStream& is) |
---|
[219] | 257 | { |
---|
| 258 | StdSize nbatt = 0; |
---|
| 259 | is.read (reinterpret_cast<char*>(&nbatt), sizeof(StdSize)); |
---|
[509] | 260 | |
---|
[219] | 261 | for (StdSize i = 0; i < nbatt; i++) |
---|
| 262 | { |
---|
| 263 | bool hasValue = false; |
---|
| 264 | StdSize size = 0; |
---|
| 265 | is.read (reinterpret_cast<char*>(&size), sizeof(StdSize)); |
---|
| 266 | StdString key(size, ' '); |
---|
[581] | 267 | is.read (const_cast<char *>(key.data()), size* sizeof(char)); |
---|
[509] | 268 | |
---|
[219] | 269 | if (!this->hasAttribute(key)) |
---|
[581] | 270 | ERROR("CAttributeMap::fromBinary(StdIStream& is)", |
---|
[219] | 271 | << "[ key = " << key << "] key not found !"); |
---|
[509] | 272 | |
---|
[219] | 273 | is.read (reinterpret_cast<char*>(&hasValue), sizeof(bool)); |
---|
[509] | 274 | |
---|
| 275 | if (hasValue) |
---|
[219] | 276 | this->operator[](key)->fromBinary(is); |
---|
| 277 | } |
---|
| 278 | } |
---|
[509] | 279 | */ |
---|
[1105] | 280 | |
---|
| 281 | |
---|
[313] | 282 | void CAttributeMap::generateCInterface(ostream& oss, const string& className) |
---|
| 283 | { |
---|
| 284 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
| 285 | for (; it != end; it++) |
---|
| 286 | { |
---|
[778] | 287 | if (it->second->isPublic()) |
---|
| 288 | { |
---|
| 289 | oss << std::endl << iendl; |
---|
| 290 | it->second->generateCInterface(oss, className); |
---|
| 291 | oss << iendl; |
---|
| 292 | it->second->generateCInterfaceIsDefined(oss, className); |
---|
| 293 | } |
---|
[313] | 294 | } |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | void CAttributeMap::generateFortran2003Interface(ostream& oss, const string& className) |
---|
| 298 | { |
---|
| 299 | SuperClassMap::const_iterator it = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
| 300 | for (; it != end; it++) |
---|
| 301 | { |
---|
[778] | 302 | if (it->second->isPublic()) |
---|
| 303 | { |
---|
| 304 | oss << std::endl << iendl; |
---|
| 305 | it->second->generateFortran2003Interface(oss, className); |
---|
| 306 | oss << iendl; |
---|
| 307 | it->second->generateFortran2003InterfaceIsDefined(oss, className); |
---|
| 308 | } |
---|
[313] | 309 | } |
---|
[509] | 310 | } |
---|
| 311 | |
---|
[219] | 312 | ///-------------------------------------------------------------- |
---|
| 313 | |
---|
[313] | 314 | void CAttributeMap::generateFortranInterface_hdl_(ostream& oss, const string& className) |
---|
| 315 | { |
---|
[581] | 316 | oss << "SUBROUTINE xios(set_" << className << "_attr_hdl_) &" << iendl++; |
---|
| 317 | SuperClassMap::const_iterator it; |
---|
[313] | 318 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 319 | |
---|
[649] | 320 | long startPos = oss.tellp(); |
---|
[509] | 321 | |
---|
[649] | 322 | oss << "( " << className << "_hdl"; |
---|
[581] | 323 | for (it = begin; it != end; it++) |
---|
[313] | 324 | { |
---|
[778] | 325 | if (it->second->isPublic()) |
---|
[313] | 326 | { |
---|
[778] | 327 | oss << ", " << it->second->getName() << "_"; |
---|
| 328 | if (oss.tellp() - startPos > 90) |
---|
| 329 | { |
---|
| 330 | oss << " &" << iendl; |
---|
| 331 | startPos = oss.tellp(); |
---|
| 332 | } |
---|
[313] | 333 | } |
---|
| 334 | } |
---|
[649] | 335 | oss << " )"; |
---|
| 336 | oss << std::endl; |
---|
[581] | 337 | oss << iendl; |
---|
[509] | 338 | |
---|
[581] | 339 | oss << "IMPLICIT NONE" << iendl++; |
---|
| 340 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
[509] | 341 | |
---|
[581] | 342 | for (it = begin; it != end; it++) |
---|
[313] | 343 | { |
---|
[778] | 344 | if (it->second->isPublic()) |
---|
| 345 | { |
---|
| 346 | oss << iendl; |
---|
| 347 | it->second->generateFortranInterfaceDeclaration_(oss, className); |
---|
| 348 | } |
---|
[313] | 349 | } |
---|
[509] | 350 | |
---|
[581] | 351 | for (it = begin; it != end; it++) |
---|
[313] | 352 | { |
---|
[778] | 353 | if (it->second->isPublic()) |
---|
| 354 | { |
---|
| 355 | oss << std::endl << iendl; |
---|
| 356 | it->second->generateFortranInterfaceBody_(oss, className); |
---|
| 357 | } |
---|
[313] | 358 | } |
---|
[509] | 359 | |
---|
[581] | 360 | oss << std::endl << (iendl -= 2); |
---|
| 361 | oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl_)" << std::endl; |
---|
[509] | 362 | } |
---|
| 363 | |
---|
[313] | 364 | void CAttributeMap::generateFortranInterfaceGet_hdl_(ostream& oss, const string& className) |
---|
| 365 | { |
---|
[581] | 366 | oss << "SUBROUTINE xios(get_" << className << "_attr_hdl_) &" << iendl++; |
---|
| 367 | SuperClassMap::const_iterator it; |
---|
[313] | 368 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 369 | |
---|
[649] | 370 | long startPos = oss.tellp(); |
---|
[509] | 371 | |
---|
[649] | 372 | oss << "( " << className << "_hdl"; |
---|
[581] | 373 | for (it = begin; it != end; it++) |
---|
[313] | 374 | { |
---|
[778] | 375 | if (it->second->isPublic()) |
---|
[313] | 376 | { |
---|
[778] | 377 | oss << ", " << it->second->getName() << "_"; |
---|
| 378 | if (oss.tellp() - startPos > 90) |
---|
| 379 | { |
---|
| 380 | oss << " &" << iendl; |
---|
| 381 | startPos = oss.tellp(); |
---|
| 382 | } |
---|
[313] | 383 | } |
---|
| 384 | } |
---|
[649] | 385 | oss << " )"; |
---|
| 386 | oss << std::endl; |
---|
[581] | 387 | oss << iendl; |
---|
[509] | 388 | |
---|
[581] | 389 | oss << "IMPLICIT NONE" << iendl++; |
---|
| 390 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
[509] | 391 | |
---|
[581] | 392 | for (it = begin; it != end; it++) |
---|
[313] | 393 | { |
---|
[778] | 394 | if (it->second->isPublic()) |
---|
| 395 | { |
---|
| 396 | oss << iendl; |
---|
| 397 | it->second->generateFortranInterfaceGetDeclaration_(oss, className); |
---|
| 398 | } |
---|
[313] | 399 | } |
---|
[509] | 400 | |
---|
[581] | 401 | for (it = begin; it != end; it++) |
---|
[313] | 402 | { |
---|
[778] | 403 | if (it->second->isPublic()) |
---|
| 404 | { |
---|
| 405 | oss << std::endl << iendl; |
---|
| 406 | it->second->generateFortranInterfaceGetBody_(oss, className); |
---|
| 407 | } |
---|
[313] | 408 | } |
---|
[509] | 409 | |
---|
[581] | 410 | oss << std::endl << (iendl -= 2); |
---|
| 411 | oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl_)" << std::endl; |
---|
[509] | 412 | } |
---|
| 413 | |
---|
[432] | 414 | void CAttributeMap::generateFortranInterfaceIsDefined_hdl_(ostream& oss, const string& className) |
---|
| 415 | { |
---|
[581] | 416 | oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl_) &" << iendl++; |
---|
| 417 | SuperClassMap::const_iterator it; |
---|
[432] | 418 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 419 | |
---|
[649] | 420 | long startPos = oss.tellp(); |
---|
[509] | 421 | |
---|
[649] | 422 | oss << "( " << className << "_hdl"; |
---|
[581] | 423 | for (it = begin; it != end; it++) |
---|
[432] | 424 | { |
---|
[778] | 425 | if (it->second->isPublic()) |
---|
[432] | 426 | { |
---|
[778] | 427 | oss << ", " << it->second->getName() << "_"; |
---|
| 428 | if (oss.tellp() - startPos > 90) |
---|
| 429 | { |
---|
| 430 | oss << " &" << iendl; |
---|
| 431 | startPos = oss.tellp(); |
---|
| 432 | } |
---|
[432] | 433 | } |
---|
| 434 | } |
---|
[649] | 435 | oss << " )"; |
---|
| 436 | oss << std::endl; |
---|
[581] | 437 | oss << iendl; |
---|
[509] | 438 | |
---|
[581] | 439 | oss << "IMPLICIT NONE" << iendl++; |
---|
| 440 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
[509] | 441 | |
---|
[581] | 442 | for (it = begin; it != end; it++) |
---|
[432] | 443 | { |
---|
[778] | 444 | if (it->second->isPublic()) |
---|
| 445 | { |
---|
| 446 | oss << iendl; |
---|
| 447 | it->second->generateFortranInterfaceIsDefinedDeclaration_(oss, className); |
---|
| 448 | } |
---|
[432] | 449 | } |
---|
[509] | 450 | |
---|
[581] | 451 | for (it = begin; it != end; it++) |
---|
[432] | 452 | { |
---|
[778] | 453 | if (it->second->isPublic()) |
---|
| 454 | { |
---|
| 455 | oss << std::endl << iendl; |
---|
| 456 | it->second->generateFortranInterfaceIsDefinedBody_(oss, className); |
---|
| 457 | } |
---|
[432] | 458 | } |
---|
[509] | 459 | |
---|
[581] | 460 | oss << std::endl << (iendl -= 2); |
---|
| 461 | oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl_)" << std::endl; |
---|
[509] | 462 | } |
---|
| 463 | |
---|
[313] | 464 | void CAttributeMap::generateFortranInterface_hdl(ostream& oss, const string& className) |
---|
| 465 | { |
---|
[581] | 466 | oss << "SUBROUTINE xios(set_" << className << "_attr_hdl) &" << iendl++; |
---|
| 467 | SuperClassMap::const_iterator it; |
---|
[313] | 468 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 469 | |
---|
[649] | 470 | long startPos = oss.tellp(); |
---|
| 471 | |
---|
| 472 | oss << "( " << className << "_hdl"; |
---|
[581] | 473 | for (it = begin; it != end; it++) |
---|
[313] | 474 | { |
---|
[778] | 475 | if (it->second->isPublic()) |
---|
[313] | 476 | { |
---|
[778] | 477 | oss << ", " << it->second->getName(); |
---|
| 478 | if (oss.tellp() - startPos > 90) |
---|
| 479 | { |
---|
| 480 | oss << " &" << iendl; |
---|
| 481 | startPos = oss.tellp(); |
---|
| 482 | } |
---|
[313] | 483 | } |
---|
| 484 | } |
---|
[649] | 485 | oss << " )"; |
---|
| 486 | oss << std::endl; |
---|
[581] | 487 | oss << iendl; |
---|
[509] | 488 | |
---|
[581] | 489 | oss << "IMPLICIT NONE" << iendl++; |
---|
| 490 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
[509] | 491 | |
---|
[581] | 492 | for (it = begin; it != end; it++) |
---|
[313] | 493 | { |
---|
[778] | 494 | if (it->second->isPublic()) |
---|
| 495 | { |
---|
| 496 | oss << iendl; |
---|
| 497 | it->second->generateFortranInterfaceDeclaration(oss, className); |
---|
| 498 | } |
---|
[313] | 499 | } |
---|
[509] | 500 | |
---|
[581] | 501 | oss << std::endl << iendl; |
---|
[509] | 502 | |
---|
[581] | 503 | oss << "CALL xios(set_" << className << "_attr_hdl_) &" << iendl; |
---|
[509] | 504 | |
---|
[649] | 505 | startPos = oss.tellp(); |
---|
| 506 | |
---|
| 507 | oss << "( " << className << "_hdl"; |
---|
[581] | 508 | for (it = begin; it != end; it++) |
---|
[313] | 509 | { |
---|
[778] | 510 | if (it->second->isPublic()) |
---|
[313] | 511 | { |
---|
[778] | 512 | oss << ", " << it->second->getName(); |
---|
| 513 | if (oss.tellp() - startPos > 90) |
---|
| 514 | { |
---|
| 515 | oss << " &" << iendl; |
---|
| 516 | startPos = oss.tellp(); |
---|
| 517 | } |
---|
[313] | 518 | } |
---|
| 519 | } |
---|
[649] | 520 | oss << " )"; |
---|
[509] | 521 | |
---|
[581] | 522 | oss << std::endl << (iendl -= 2); |
---|
| 523 | oss << "END SUBROUTINE xios(set_" << className << "_attr_hdl)" << std::endl; |
---|
[509] | 524 | } |
---|
| 525 | |
---|
[313] | 526 | void CAttributeMap::generateFortranInterfaceGet_hdl(ostream& oss, const string& className) |
---|
| 527 | { |
---|
[581] | 528 | oss << "SUBROUTINE xios(get_" << className << "_attr_hdl) &" << iendl++; |
---|
| 529 | SuperClassMap::const_iterator it; |
---|
[313] | 530 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 531 | |
---|
[649] | 532 | long startPos = oss.tellp(); |
---|
| 533 | |
---|
| 534 | oss << "( " << className << "_hdl"; |
---|
[581] | 535 | for (it = begin; it != end; it++) |
---|
[313] | 536 | { |
---|
[778] | 537 | if (it->second->isPublic()) |
---|
[313] | 538 | { |
---|
[778] | 539 | oss << ", " << it->second->getName(); |
---|
| 540 | if (oss.tellp() - startPos > 90) |
---|
| 541 | { |
---|
| 542 | oss << " &" << iendl; |
---|
| 543 | startPos = oss.tellp(); |
---|
| 544 | } |
---|
[313] | 545 | } |
---|
| 546 | } |
---|
[649] | 547 | oss << " )"; |
---|
| 548 | oss << std::endl; |
---|
[581] | 549 | oss << iendl; |
---|
[509] | 550 | |
---|
[581] | 551 | oss << "IMPLICIT NONE" << iendl++; |
---|
| 552 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
[509] | 553 | |
---|
[581] | 554 | for (it = begin; it != end; it++) |
---|
[313] | 555 | { |
---|
[778] | 556 | if (it->second->isPublic()) |
---|
| 557 | { |
---|
| 558 | oss << iendl; |
---|
| 559 | it->second->generateFortranInterfaceGetDeclaration(oss, className); |
---|
| 560 | } |
---|
[313] | 561 | } |
---|
[509] | 562 | |
---|
[581] | 563 | oss << std::endl << iendl; |
---|
[509] | 564 | |
---|
[581] | 565 | oss << "CALL xios(get_" << className << "_attr_hdl_) &" << iendl; |
---|
[509] | 566 | |
---|
[649] | 567 | startPos = oss.tellp(); |
---|
| 568 | |
---|
| 569 | oss << "( " << className << "_hdl"; |
---|
[581] | 570 | for (it = begin; it != end; it++) |
---|
[313] | 571 | { |
---|
[778] | 572 | if (it->second->isPublic()) |
---|
[313] | 573 | { |
---|
[778] | 574 | oss << ", " << it->second->getName(); |
---|
| 575 | if (oss.tellp() - startPos > 90) |
---|
| 576 | { |
---|
| 577 | oss << " &" << iendl; |
---|
| 578 | startPos = oss.tellp(); |
---|
| 579 | } |
---|
[313] | 580 | } |
---|
| 581 | } |
---|
[649] | 582 | oss << " )"; |
---|
[509] | 583 | |
---|
[581] | 584 | oss << std::endl << (iendl -= 2); |
---|
| 585 | oss << "END SUBROUTINE xios(get_" << className << "_attr_hdl)" << std::endl; |
---|
[509] | 586 | } |
---|
[432] | 587 | |
---|
| 588 | void CAttributeMap::generateFortranInterfaceIsDefined_hdl(ostream& oss, const string& className) |
---|
| 589 | { |
---|
[581] | 590 | oss << "SUBROUTINE xios(is_defined_" << className << "_attr_hdl) &" << iendl++; |
---|
| 591 | SuperClassMap::const_iterator it; |
---|
[432] | 592 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 593 | |
---|
[649] | 594 | long startPos = oss.tellp(); |
---|
| 595 | |
---|
| 596 | oss << "( " << className << "_hdl"; |
---|
[581] | 597 | for (it = begin; it != end; it++) |
---|
[432] | 598 | { |
---|
[778] | 599 | if (it->second->isPublic()) |
---|
[432] | 600 | { |
---|
[778] | 601 | oss << ", " << it->second->getName(); |
---|
| 602 | if (oss.tellp() - startPos > 90) |
---|
| 603 | { |
---|
| 604 | oss << " &" << iendl; |
---|
| 605 | startPos = oss.tellp(); |
---|
| 606 | } |
---|
[432] | 607 | } |
---|
| 608 | } |
---|
[649] | 609 | oss << " )"; |
---|
| 610 | oss << std::endl; |
---|
[581] | 611 | oss << iendl; |
---|
[509] | 612 | |
---|
[581] | 613 | oss << "IMPLICIT NONE" << iendl++; |
---|
| 614 | oss << "TYPE(txios(" << className << ")) , INTENT(IN) :: " << className << "_hdl"; |
---|
[509] | 615 | |
---|
[581] | 616 | for (it = begin; it != end; it++) |
---|
[432] | 617 | { |
---|
[778] | 618 | if (it->second->isPublic()) |
---|
| 619 | { |
---|
| 620 | oss << iendl; |
---|
| 621 | it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className); |
---|
| 622 | } |
---|
[432] | 623 | } |
---|
[509] | 624 | |
---|
[581] | 625 | oss << std::endl << iendl; |
---|
[509] | 626 | |
---|
[581] | 627 | oss << "CALL xios(is_defined_" << className << "_attr_hdl_) &" << iendl; |
---|
[509] | 628 | |
---|
[649] | 629 | startPos = oss.tellp(); |
---|
| 630 | |
---|
| 631 | oss << "( " << className << "_hdl"; |
---|
[581] | 632 | for (it = begin; it != end; it++) |
---|
[432] | 633 | { |
---|
[778] | 634 | if (it->second->isPublic()) |
---|
[432] | 635 | { |
---|
[778] | 636 | oss << ", " << it->second->getName(); |
---|
| 637 | if (oss.tellp() - startPos > 90) |
---|
| 638 | { |
---|
| 639 | oss << " &" << iendl; |
---|
| 640 | startPos = oss.tellp(); |
---|
| 641 | } |
---|
[432] | 642 | } |
---|
| 643 | } |
---|
[649] | 644 | oss << " )"; |
---|
[509] | 645 | |
---|
[581] | 646 | oss << std::endl << (iendl -= 2); |
---|
| 647 | oss << "END SUBROUTINE xios(is_defined_" << className << "_attr_hdl)" << std::endl; |
---|
[509] | 648 | } |
---|
[432] | 649 | |
---|
[313] | 650 | void CAttributeMap::generateFortranInterface_id(ostream& oss, const string& className) |
---|
| 651 | { |
---|
[581] | 652 | oss << "SUBROUTINE xios(set_" << className << "_attr) &" << iendl++; |
---|
| 653 | SuperClassMap::const_iterator it; |
---|
[313] | 654 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 655 | |
---|
[649] | 656 | long startPos = oss.tellp(); |
---|
| 657 | |
---|
| 658 | oss << "( " << className << "_id"; |
---|
[581] | 659 | for (it = begin; it != end; it++) |
---|
[313] | 660 | { |
---|
[778] | 661 | if (it->second->isPublic()) |
---|
[313] | 662 | { |
---|
[778] | 663 | oss << ", " << it->second->getName(); |
---|
| 664 | if (oss.tellp() - startPos > 90) |
---|
| 665 | { |
---|
| 666 | oss << " &" << iendl; |
---|
| 667 | startPos = oss.tellp(); |
---|
| 668 | } |
---|
[313] | 669 | } |
---|
| 670 | } |
---|
[649] | 671 | oss << " )"; |
---|
| 672 | oss << std::endl; |
---|
[581] | 673 | oss << iendl; |
---|
[509] | 674 | |
---|
[581] | 675 | oss << "IMPLICIT NONE" << iendl++; |
---|
[313] | 676 | |
---|
[581] | 677 | oss << "TYPE(txios(" << className << ")) :: " << className << "_hdl" << iendl; |
---|
| 678 | oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id"; |
---|
[509] | 679 | |
---|
[581] | 680 | for (it = begin; it != end; it++) |
---|
[313] | 681 | { |
---|
[778] | 682 | if (it->second->isPublic()) |
---|
| 683 | { |
---|
| 684 | oss << iendl; |
---|
| 685 | it->second->generateFortranInterfaceDeclaration(oss, className); |
---|
| 686 | } |
---|
[313] | 687 | } |
---|
[509] | 688 | |
---|
[581] | 689 | oss << std::endl << iendl; |
---|
[966] | 690 | oss << "CALL xios(get_" << className << "_handle) &" << iendl; |
---|
| 691 | oss << "(" << className << "_id," << className << "_hdl)" << iendl; |
---|
[581] | 692 | oss << "CALL xios(set_" << className << "_attr_hdl_) &" << iendl; |
---|
[649] | 693 | |
---|
| 694 | startPos = oss.tellp(); |
---|
| 695 | |
---|
| 696 | oss << "( " << className << "_hdl"; |
---|
[581] | 697 | for (it = begin; it != end; it++) |
---|
[313] | 698 | { |
---|
[778] | 699 | if (it->second->isPublic()) |
---|
[313] | 700 | { |
---|
[778] | 701 | oss << ", " << it->second->getName(); |
---|
| 702 | if (oss.tellp() - startPos > 90) |
---|
| 703 | { |
---|
| 704 | oss << " &" << iendl; |
---|
| 705 | startPos = oss.tellp(); |
---|
| 706 | } |
---|
[313] | 707 | } |
---|
| 708 | } |
---|
[649] | 709 | oss << " )"; |
---|
[509] | 710 | |
---|
[581] | 711 | oss << std::endl << (iendl -= 2); |
---|
| 712 | oss << "END SUBROUTINE xios(set_" << className << "_attr)" << std::endl; |
---|
[509] | 713 | } |
---|
| 714 | |
---|
[313] | 715 | void CAttributeMap::generateFortranInterfaceGet_id(ostream& oss, const string& className) |
---|
| 716 | { |
---|
[581] | 717 | oss << "SUBROUTINE xios(get_" << className << "_attr) &" << iendl++; |
---|
| 718 | SuperClassMap::const_iterator it; |
---|
[313] | 719 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 720 | |
---|
[649] | 721 | long startPos = oss.tellp(); |
---|
| 722 | |
---|
| 723 | oss << "( " << className << "_id"; |
---|
[581] | 724 | for (it = begin; it != end; it++) |
---|
[313] | 725 | { |
---|
[778] | 726 | if (it->second->isPublic()) |
---|
[313] | 727 | { |
---|
[778] | 728 | oss << ", " << it->second->getName(); |
---|
| 729 | if (oss.tellp() - startPos > 90) |
---|
| 730 | { |
---|
| 731 | oss << " &" << iendl; |
---|
| 732 | startPos = oss.tellp(); |
---|
| 733 | } |
---|
[313] | 734 | } |
---|
| 735 | } |
---|
[649] | 736 | oss << " )"; |
---|
| 737 | oss << std::endl; |
---|
[581] | 738 | oss << iendl; |
---|
[509] | 739 | |
---|
[581] | 740 | oss << "IMPLICIT NONE" << iendl++; |
---|
[313] | 741 | |
---|
[581] | 742 | oss << "TYPE(txios(" << className << ")) :: " << className << "_hdl" << iendl; |
---|
| 743 | oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id"; |
---|
[509] | 744 | |
---|
[581] | 745 | for (it = begin; it != end; it++) |
---|
[313] | 746 | { |
---|
[778] | 747 | if (it->second->isPublic()) |
---|
| 748 | { |
---|
| 749 | oss << iendl; |
---|
| 750 | it->second->generateFortranInterfaceGetDeclaration(oss, className); |
---|
| 751 | } |
---|
[313] | 752 | } |
---|
[509] | 753 | |
---|
[581] | 754 | oss << std::endl << iendl; |
---|
[966] | 755 | oss << "CALL xios(get_" << className << "_handle) &" << iendl; |
---|
| 756 | oss << "(" << className << "_id," << className << "_hdl)" << iendl; |
---|
[581] | 757 | oss << "CALL xios(get_" << className << "_attr_hdl_) &" << iendl; |
---|
[649] | 758 | |
---|
| 759 | startPos = oss.tellp(); |
---|
| 760 | |
---|
| 761 | oss << "( " << className << "_hdl"; |
---|
[581] | 762 | for (it = begin; it != end; it++) |
---|
[313] | 763 | { |
---|
[778] | 764 | if (it->second->isPublic()) |
---|
[313] | 765 | { |
---|
[778] | 766 | oss << ", " << it->second->getName(); |
---|
| 767 | if (oss.tellp() - startPos > 90) |
---|
| 768 | { |
---|
| 769 | oss << " &" << iendl; |
---|
| 770 | startPos = oss.tellp(); |
---|
| 771 | } |
---|
[313] | 772 | } |
---|
| 773 | } |
---|
[649] | 774 | oss << " )"; |
---|
[509] | 775 | |
---|
[581] | 776 | oss << std::endl << (iendl -= 2); |
---|
| 777 | oss << "END SUBROUTINE xios(get_" << className << "_attr)" << std::endl; |
---|
[509] | 778 | } |
---|
| 779 | |
---|
[432] | 780 | void CAttributeMap::generateFortranInterfaceIsDefined_id(ostream& oss, const string& className) |
---|
| 781 | { |
---|
[581] | 782 | oss << "SUBROUTINE xios(is_defined_" << className << "_attr) &" << iendl++; |
---|
| 783 | SuperClassMap::const_iterator it; |
---|
[432] | 784 | SuperClassMap::const_iterator begin = SuperClassMap::begin(), end = SuperClassMap::end(); |
---|
[509] | 785 | |
---|
[649] | 786 | long startPos = oss.tellp(); |
---|
| 787 | |
---|
| 788 | oss << "( " << className << "_id"; |
---|
[581] | 789 | for (it = begin; it != end; it++) |
---|
[432] | 790 | { |
---|
[778] | 791 | if (it->second->isPublic()) |
---|
[432] | 792 | { |
---|
[778] | 793 | oss << ", " << it->second->getName(); |
---|
| 794 | if (oss.tellp() - startPos > 90) |
---|
| 795 | { |
---|
| 796 | oss << " &" << iendl; |
---|
| 797 | startPos = oss.tellp(); |
---|
| 798 | } |
---|
[432] | 799 | } |
---|
| 800 | } |
---|
[649] | 801 | oss << " )"; |
---|
| 802 | oss << std::endl; |
---|
[581] | 803 | oss << iendl; |
---|
[509] | 804 | |
---|
[581] | 805 | oss << "IMPLICIT NONE" << iendl++; |
---|
[432] | 806 | |
---|
[581] | 807 | oss << "TYPE(txios(" << className << ")) :: " << className << "_hdl" << iendl; |
---|
| 808 | oss << "CHARACTER(LEN=*), INTENT(IN) ::" << className << "_id"; |
---|
[509] | 809 | |
---|
[581] | 810 | for (it = begin; it != end; it++) |
---|
[432] | 811 | { |
---|
[778] | 812 | if (it->second->isPublic()) |
---|
| 813 | { |
---|
| 814 | oss << iendl; |
---|
| 815 | it->second->generateFortranInterfaceIsDefinedDeclaration(oss, className); |
---|
| 816 | } |
---|
[432] | 817 | } |
---|
[509] | 818 | |
---|
[581] | 819 | oss << std::endl << iendl; |
---|
[966] | 820 | oss << "CALL xios(get_" << className << "_handle) &" << iendl; |
---|
| 821 | oss << "(" << className << "_id," << className << "_hdl)" << iendl; |
---|
[581] | 822 | oss << "CALL xios(is_defined_" << className << "_attr_hdl_) &" << iendl; |
---|
[649] | 823 | |
---|
| 824 | startPos = oss.tellp(); |
---|
| 825 | |
---|
| 826 | oss << "( " << className << "_hdl"; |
---|
[581] | 827 | for (it = begin; it != end; it++) |
---|
[432] | 828 | { |
---|
[778] | 829 | if (it->second->isPublic()) |
---|
[432] | 830 | { |
---|
[778] | 831 | oss << ", " << it->second->getName(); |
---|
| 832 | if (oss.tellp() - startPos > 90) |
---|
| 833 | { |
---|
| 834 | oss << " &" << iendl; |
---|
| 835 | startPos = oss.tellp(); |
---|
| 836 | } |
---|
[432] | 837 | } |
---|
| 838 | } |
---|
[649] | 839 | oss << " )"; |
---|
[509] | 840 | |
---|
[581] | 841 | oss << std::endl << (iendl -= 2); |
---|
| 842 | oss << "END SUBROUTINE xios(is_defined_" << className << "_attr)" << std::endl; |
---|
[509] | 843 | } |
---|
[591] | 844 | } // namespace xios |
---|