VsRegistry.C 40.7 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * VsRegistry.cpp
 *
 *  Created on: Apr 30, 2010
 *      Author: mdurant
 */

#include "VsRegistry.h"
apletzer's avatar
apletzer committed
9 10
#include "VsDataset.h"
#include "VsGroup.h"
11 12 13
#include "VsMesh.h"
#include "VsUtils.h"
#include "VsLog.h"
apletzer's avatar
apletzer committed
14
#include "VsAttribute.h"
15 16 17 18 19 20 21 22 23 24 25 26
#include "VsSchema.h"
#include "VsVariable.h"
#include "VsVariableWithMesh.h"
#include "VsMDMesh.h"
#include "VsMDVariable.h"
#include "VsMesh.h"

#include <sstream>

VsRegistry::VsRegistry() {
  deletingObjects = false;
  timeValue = -1;
27
  cycle = -1;
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
}

VsRegistry::~VsRegistry() {
  deleteAllObjects();
}

void VsRegistry::deleteAllObjects() {
  deletingObjects = true;
  
  //Delete the highest-level objects first
  this->deleteAllMeshes();
  this->deleteAllVariables();
  this->deleteAllVariablesWithMesh();

  //Delete the low-level objects last
  this->deleteAllDatasets();
  this->deleteAllGroups();
  
  deletingObjects = false;
}

apletzer's avatar
apletzer committed
49 50
/*********** VsGroups ***********/
void VsRegistry::add(VsGroup* group) {
51
  //check for duplicate long name
apletzer's avatar
apletzer committed
52
  VsGroup* found = this->getGroup(group->getFullName());
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  if (found) {
    VsLog::errorLog() <<"VsRegistry::add() - Group already exists with this long name: " <<group->getFullName() <<std::endl;
    return;
  }
  
  //check for duplicate short names
  found = this->getGroup(group->getShortName());
  if (found) {
    VsLog::warningLog() <<"VsRegistry::add() - Group already exists with this short name: " <<group->getShortName() <<std::endl;
  }
  
  allGroups[group->getFullName()] = group; 
  allGroupsShort[group->getShortName()] = group;
}

int VsRegistry::numGroups() {
  return allGroups.size();
}

apletzer's avatar
apletzer committed
72
void VsRegistry::remove(VsGroup* group) {
73 74 75 76 77 78 79
  if (deletingObjects)
    return;

  allGroups.erase(group->getFullName());
  allGroupsShort.erase(group->getShortName());
}

apletzer's avatar
apletzer committed
80
VsGroup* VsRegistry::getGroup(const std::string& name) {
81 82
  std::string fullName = makeCanonicalName(name);

apletzer's avatar
apletzer committed
83
  std::map<std::string, VsGroup*>::iterator it = allGroups.find(fullName);
84 85 86 87 88 89 90 91 92 93 94 95
  if (it != allGroups.end()) {
    return (*it).second;
  }
  
  it = allGroupsShort.find(fullName);
  if (it != allGroupsShort.end()) {
    return (*it).second;
  }
  return NULL;
}

void VsRegistry::deleteAllGroups() {
apletzer's avatar
apletzer committed
96
  for (std::map<std::string, VsGroup*>::const_iterator it = allGroups.begin();
97
          it != allGroups.end(); it++) {
apletzer's avatar
apletzer committed
98
        VsGroup* group = it->second;
99 100 101 102 103 104 105
        delete(group);
    }

  allGroups.clear();
  allGroupsShort.clear();
}

apletzer's avatar
apletzer committed
106 107
void VsRegistry::writeAllGroups() const {
  VsLog::debugLog() <<"********** BEGIN VsGroups *********" <<std::endl;
108
  
apletzer's avatar
apletzer committed
109
  for (std::map<std::string, VsGroup*>::const_iterator it = allGroups.begin();
110
        it != allGroups.end(); it++) {
apletzer's avatar
apletzer committed
111
      VsGroup* group = it->second;
112 113 114
      group->write();
  }
    
apletzer's avatar
apletzer committed
115
  VsLog::debugLog() <<"********** END VsGroups *********" <<std::endl;
116 117 118 119
}

void VsRegistry::buildGroupObjects() {
  VsLog::debugLog() <<"VsRegistry::buildGroupObjects - Entering." <<std::endl;
apletzer's avatar
apletzer committed
120
  for (std::map<std::string, VsGroup*>::const_iterator it = allGroups.begin();
121
      it != allGroups.end(); it++) {
apletzer's avatar
apletzer committed
122
    VsGroup* group = it->second;
123 124 125
    VsLog::debugLog() <<"VsRegistry::buildGroupObjects - Building object " <<group->getFullName() <<std::endl;
    
    //What is the declared type of this group?
apletzer's avatar
apletzer committed
126
    VsAttribute* typeAtt = group->getAttribute(VsSchema::typeAtt);
127 128 129 130 131 132 133 134 135 136 137 138 139
    if (!typeAtt) {
      VsLog::warningLog() <<"VsRegistry::buildGroupObjects - unable to find attribute " <<VsSchema::typeAtt
        <<".  Skipping object " <<group->getFullName() <<std::endl;
      continue;
    }
    
    std::string type;
    typeAtt->getStringValue(&type);
    VsLog::debugLog() <<"VsRegistry::buildGroupObjects - group is of type " <<type <<std::endl;
    if (type == VsSchema::meshKey) {
      VsMesh::buildObject(group);
    } else if (type == VsSchema::vsVarsKey) {
      buildExpressions(group);
140 141 142 143
    } else if (type == VsSchema::timeKey) {
      loadTime(group);
    } else if (type == VsSchema::runInfoKey) {
      loadRunInfo(group);
144 145 146 147 148 149 150 151
    } else {
      VsLog::debugLog() <<"VsRegistry::buildGroupObjects - object is of unrecognized type " <<type <<std::endl;
    }
  }
    
  VsLog::debugLog() <<"VsRegistry::buildGroupObjects - Returning." <<std::endl;
}

apletzer's avatar
apletzer committed
152 153
void VsRegistry::loadTime(VsGroup* group) {
  VsLog::debugLog() <<"VsRegistry::loadTime() - Group is NULL?" << "'" << group << "'" <<std::endl;
154 155 156 157 158 159 160
  if (!group) {
    VsLog::debugLog() <<"VsRegistry::loadTime() - Group is NULL?" <<std::endl;
    return;
  }
  
  //try to load a value for "time"
  double foundTime = -1.0;
apletzer's avatar
apletzer committed
161
  VsAttribute* timeAtt = group->getAttribute(VsSchema::timeAtt);
162 163
  if (timeAtt) {
    std::vector<float> in;
apletzer's avatar
apletzer committed
164
    int err = timeAtt->getFloatVectorValue(&in);
165 166 167 168
    if (err < 0) {
      VsLog::debugLog() <<"VsRegistry::loadTime(): Error " <<err <<" while trying to load time attribute." <<std::endl;
    } else {
      foundTime = in[0];
169
      VsLog::debugLog() <<"VsRegistry::loadTime() - loaded time: " <<foundTime  <<std::endl;
170 171 172
    }
  }

173 174
  //try to load a value for "cycle"
  int foundCycle = -1;
apletzer's avatar
apletzer committed
175
  VsAttribute* cycleAtt = group->getAttribute(VsSchema::cycleAtt);
176
  if (cycleAtt) {
177
    std::vector<int> in;
apletzer's avatar
apletzer committed
178
    int err = cycleAtt->getIntVectorValue(&in);
179
    if (err < 0) {
180
      VsLog::debugLog() <<"VsRegistry::loadTime(): Error " <<err <<" while trying to load cycle attribute." <<std::endl;
181
    } else {
182 183
      foundCycle = in[0];
      VsLog::debugLog() <<"VsRegistry::loadTime() - loaded cycle: " <<foundCycle <<std::endl;
184 185 186 187 188 189 190
    }
  }
 
  //check for existing time data, and compare
  if ((foundTime != -1) && hasTime() && (foundTime != getTime())) {
    VsLog::warningLog() <<"VsRegistry::loadTime() - was asked to load time data again, but time data already exists." <<std::endl;
    VsLog::warningLog() <<"VsRegistry::loadTime() - and is in conflict: " <<foundTime <<" vs " <<getTime() <<std::endl;
191 192
  } else {
    timeValue = foundTime;
193 194
  }
  
195 196 197
  if ((foundCycle != -1) && hasCycle() && (foundCycle != getCycle())) {
    VsLog::warningLog() <<"VsRegistry::loadTime() - was asked to load cycle data again, but cycle data already exists." <<std::endl;
    VsLog::warningLog() <<"VsRegistry::loadTime() - and is in conflict: " <<foundCycle <<" vs " <<getCycle() <<std::endl;
198
  } else {
199
    cycle = foundCycle;
200
  }
201
}
202

apletzer's avatar
apletzer committed
203
void VsRegistry::loadRunInfo(VsGroup* group) {
204 205 206 207
  if (!group) {
    VsLog::debugLog() <<"VsRegistry::loadRunInfo() - Group is NULL?" <<std::endl;
    return;
  }
208

209
  VsLog::debugLog() <<"VsRegistry::loadRunInfo() - not loading any information at this time." <<std::endl;
210 211
}

apletzer's avatar
apletzer committed
212 213
/*********** VsDatasets***********/
void VsRegistry::add(VsDataset* dataset) {
214
  //check for duplicate long name
apletzer's avatar
apletzer committed
215
  VsDataset* found = this->getDataset(dataset->getFullName());
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  if (found) {
    VsLog::errorLog() <<"VsRegistry::add() - Dataset already exists with this long name: " <<dataset->getFullName() <<std::endl;
    return;
  }
  
  //check for duplicate short names
  found = this->getDataset(dataset->getShortName());
  if (found) {
    VsLog::warningLog() <<"VsRegistry::add() - Dataset already exists with this short name: " <<dataset->getShortName() <<std::endl;
  }
  
  allDatasets[dataset->getFullName()] = dataset; 
  allDatasetsShort[dataset->getShortName()] = dataset;
}

int VsRegistry::numDatasets() {
  return allDatasets.size();
}

apletzer's avatar
apletzer committed
235
void VsRegistry::remove(VsDataset* dataset) {
236 237 238 239 240 241 242
  if (deletingObjects)
    return;

  allDatasets.erase(dataset->getFullName());
  allDatasetsShort.erase(dataset->getShortName());
}

apletzer's avatar
apletzer committed
243
VsDataset* VsRegistry::getDataset(const std::string& name) {
244 245
  std::string fullName = makeCanonicalName(name);

apletzer's avatar
apletzer committed
246
  std::map<std::string, VsDataset*>::iterator it = allDatasets.find(fullName);
247 248 249 250 251 252 253 254 255 256 257 258
  if (it != allDatasets.end()) {
    return (*it).second;
  }
  
  it = allDatasetsShort.find(fullName);
  if (it != allDatasetsShort.end()) {
    return (*it).second;
  }
  return NULL;
}

void VsRegistry::deleteAllDatasets() {
apletzer's avatar
apletzer committed
259
  for (std::map<std::string, VsDataset*>::const_iterator it = allDatasets.begin();
260
        it != allDatasets.end(); it++) {
apletzer's avatar
apletzer committed
261
      VsDataset* dataset = it->second;
262 263 264 265 266 267 268
      delete(dataset);
  }

  allDatasets.clear();
  allDatasetsShort.clear();
}

apletzer's avatar
apletzer committed
269 270
void VsRegistry::writeAllDatasets() const {
  VsLog::debugLog() <<"********** BEGIN VsDatasets *********" <<std::endl;
271
  
apletzer's avatar
apletzer committed
272
  for (std::map<std::string, VsDataset*>::const_iterator it = allDatasets.begin();
273
        it != allDatasets.end(); it++) {
apletzer's avatar
apletzer committed
274
      VsDataset* dataset = it->second;
275 276 277
      dataset->write();
  }
    
apletzer's avatar
apletzer committed
278
  VsLog::debugLog() <<"********** END VsDatasets *********" <<std::endl;
279 280 281 282 283 284 285
}

void VsRegistry::buildDatasetObjects() {
  VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - Entering."  <<std::endl;

  //First pass just do meshes
  //But remember the variables for second pass
apletzer's avatar
apletzer committed
286 287 288
  std::vector<VsDataset*> varDatasets;
  std::vector<VsDataset*> varWithMeshDatasets;
  for (std::map<std::string, VsDataset*>::const_iterator it = allDatasets.begin();
289
     it != allDatasets.end(); it++)  {
apletzer's avatar
apletzer committed
290
    VsDataset* dataset = it->second;
291
    VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - looking at dataset " <<dataset->getFullName() <<std::endl;
292 293 294

    //Try to determine the type of the object
    std::string type;    
apletzer's avatar
apletzer committed
295
    VsAttribute* typeAtt = dataset->getAttribute(VsSchema::typeAtt);
296
    if (!typeAtt) {
297 298 299 300 301
      VsLog::warningLog() <<"VsRegistry::buildDatasetObjects() - unable to find attribute " <<VsSchema::typeAtt <<std::endl;
      
      //If the object contains the "vsMesh" attribute, then it is probably intended to be a variable
      //So continue with that assumption
      VsLog::warningLog() <<"VsRegistry::buildDatasetObjects() - Second chance - looking for attribute " <<VsSchema::meshAtt <<std::endl;
apletzer's avatar
apletzer committed
302
      VsAttribute* meshAtt = dataset->getAttribute(VsSchema::meshAtt);
303 304 305 306 307 308 309 310 311 312
      if (meshAtt) {
        VsLog::warningLog() <<"VsRegistry::buildDatasetObjects() - Found attribute " <<VsSchema::meshAtt <<" assuming that this is a variable." <<std::endl;
        type = VsSchema::varKey;
      } else {
        VsLog::warningLog() <<"VsRegistry::buildDatasetObjects() - Did not find attribute " <<VsSchema::meshAtt
                  <<", second chance option has failed.  Skipping object: " <<dataset->getFullName() <<std::endl;
        continue;
      }
    } else {
      typeAtt->getStringValue(&type);
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
    }
    
    VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - object is of type " <<type <<std::endl;
    if (type == VsSchema::meshKey) {
      VsMesh::buildObject(dataset);
    } else if (type == VsSchema::varKey) {
      VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - Variables are built in second pass. Skipping for now." <<std::endl;
      varDatasets.push_back(dataset);
    } else if (type == VsSchema::varWithMeshKey) {
      VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - VariableWithMesh are built in second pass. Skipping for now." <<std::endl;
      varWithMeshDatasets.push_back(dataset);
    } else {
      VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - object is of unknown type!" <<std::endl;
    }
  }

  //Second pass to do all variables
apletzer's avatar
apletzer committed
330
  for (std::vector<VsDataset*>::const_iterator it = varDatasets.begin();
331
       it != varDatasets.end(); it++)  {
apletzer's avatar
apletzer committed
332
    VsDataset* dataset = *it;
333 334
    
    VsVariable* var = VsVariable::buildObject(dataset);
335
    if (var && (var->getTimeGroup() != NULL)) {
336 337 338 339 340
      loadTime(var->getTimeGroup());
    }
  }

  //Second pass to do all variables with mesh
apletzer's avatar
apletzer committed
341
  for (std::vector<VsDataset*>::const_iterator it = varWithMeshDatasets.begin();
342
       it != varWithMeshDatasets.end(); it++)  {
apletzer's avatar
apletzer committed
343
    VsDataset* dataset = *it;
344 345 346
    VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - looking at varWithMesh dataset " <<dataset->getFullName() <<std::endl;
    
    VsVariableWithMesh* var = VsVariableWithMesh::buildObject(dataset);
347
    if (var && (var->getTimeGroup() != NULL)) {
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
      loadTime(var->getTimeGroup());
    }
  }
  
  VsLog::debugLog() <<"VsRegistry::buildDatasetObjects() - Returning."  <<std::endl;
 }

/*********** VsMeshes ***********/
void VsRegistry::add(VsMesh* mesh) {
  //check for duplicate long name
  VsMesh* found = this->getMesh(mesh->getFullName());
  if (found) {
    VsLog::errorLog() <<"VsRegistry::add() - Mesh already exists with this long name: " <<mesh->getFullName() <<std::endl;
    return;
  }
  
  //check for duplicate short names
  found = this->getMesh(mesh->getShortName());
  if (found) {
    VsLog::warningLog() <<"VsRegistry::add() - Mesh already exists with this short name: " <<mesh->getShortName() <<std::endl;
  }
  
  allMeshes[mesh->getFullName()] = mesh; 
  allMeshesShort[mesh->getShortName()] = mesh;
}

int VsRegistry::numMeshes() {
  return allMeshes.size();
}

void VsRegistry::remove(VsMesh* mesh) {
  if (deletingObjects)
    return;

  allMeshes.erase(mesh->getFullName());
  allMeshesShort.erase(mesh->getShortName());
}

386
VsMesh* VsRegistry::getMesh(const std::string& name) {
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
  std::string fullName = makeCanonicalName(name);

  std::map<std::string, VsMesh*>::iterator it = allMeshes.find(fullName);
  if (it != allMeshes.end()) {
    return (*it).second;
  }
  
  it = allMeshesShort.find(fullName);
  if (it != allMeshesShort.end()) {
    return (*it).second;
  }
  return NULL;
}

void VsRegistry::deleteAllMeshes() {
  for (std::map<std::string, VsMesh*>::iterator it = allMeshes.begin();
        it != allMeshes.end(); it++) {
      VsMesh* mesh = it->second;
      delete(mesh);
  }
  
  allMeshes.clear();
  allMeshesShort.clear();
}

apletzer's avatar
apletzer committed
412
void VsRegistry::writeAllMeshes() const {
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
  if (allMeshes.empty()) {
    VsLog::debugLog() <<"*********** NO MESHES ********" <<std::endl;
    return;
  }
  
  VsLog::debugLog() <<"********** BEGIN VsMeshs *********" <<std::endl;
  
  for (std::map<std::string, VsMesh*>::const_iterator it = allMeshes.begin();
        it != allMeshes.end(); it++) {
      VsMesh* mesh = it->second;
      mesh->write();
  }
    
  VsLog::debugLog() <<"********** END VsMeshs *********" <<std::endl;
}

void VsRegistry::getAllMeshNames(std::vector<std::string>& names)  {
  std::map<std::string, VsMesh*>::const_iterator it;
  for (it = allMeshes.begin(); it != allMeshes.end(); ++it)
    names.push_back(it->first);
}

/************* MD MESHES **************/

437
VsMDMesh* VsRegistry::getMDMesh(const std::string& name) {
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  // Make name fully qualified
  std::string fullName = makeCanonicalName(name);
  
  std::map<std::string, VsMDMesh*>::iterator it = allMDMeshes.find(fullName);
  if (it != allMDMeshes.end()) {
   return it->second;
  }
  
  return NULL;
}

void VsRegistry::add(VsMDMesh* mesh) {
  //check for duplicate name
  VsMDMesh* foundMesh = this->getMDMesh(mesh->getFullName());
  if (foundMesh) {
    VsLog::errorLog() <<"VsRegistry::add() - MD Mesh already exists with this long name: " <<mesh->getFullName() <<std::endl;
    return;
  }
  
  allMDMeshes[mesh->getFullName()] = mesh;
}

void VsRegistry::remove(VsMDMesh* mesh) {
  allMDMeshes.erase(mesh->getFullName());
}

void VsRegistry::getAllMDMeshNames(std::vector<std::string>& names)  {
  std::map<std::string, VsMDMesh*>::const_iterator it;
  for (it = allMDMeshes.begin(); it != allMDMeshes.end(); ++it)
    names.push_back(it->first);
}

apletzer's avatar
apletzer committed
470
void VsRegistry::writeAllMDMeshes() const {
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
  if (allMDMeshes.empty()) {
    VsLog::debugLog() <<"*********** NO MDMESHES ********" <<std::endl;
    return;
  }
  
  VsLog::debugLog() <<"*********** BEGIN MDMESHES ********" <<std::endl;
  std::map<std::string, VsMDMesh*>::const_iterator it;
  for (it = allMDMeshes.begin(); it != allMDMeshes.end(); ++it) {
    it->second->write();
  }
  
  VsLog::debugLog() <<"*********** END MDMESHES ********" <<std::endl;
}

int VsRegistry::numMDMeshes() {
  return allMDMeshes.size();
}

VsMDMesh* VsRegistry::getMDParentForMesh(const std::string& name) {
  VsLog::debugLog() << "VsMDMesh::getMDParentForMesh(" <<name <<"): Entering." << std::endl;
  
  std::string fullName = makeCanonicalName(name);
  
  for (std::map<std::string, VsMDMesh*>::const_iterator it = allMDMeshes.begin(); it != allMDMeshes.end(); it++) {
    VsMDMesh* meshMeta = it->second;
apletzer's avatar
apletzer committed
496 497
    for (unsigned int i = 0; i < meshMeta->getNumBlocks(); i++) {
      if (fullName == makeCanonicalName(meshMeta->getBlock(i)->getFullName())) {
498 499 500 501 502 503 504 505 506 507 508 509 510
        VsLog::debugLog() << "VsMDMesh::getMDParentForMesh(" <<name <<"): Returning result." << std::endl;
        return meshMeta;
      }
    }
  }
  VsLog::debugLog() << "VsMDMesh::getMDParentForMesh(" <<name <<"): Returning NULL." << std::endl;
  return NULL;
}

VsMesh* VsRegistry::findSubordinateMDMesh(const std::string& name) {
  VsLog::debugLog() << "VsMDMesh::findSubordinateMDMesh(" <<name <<"): Entering." << std::endl;
  for (std::map<std::string, VsMDMesh*>::const_iterator it = allMDMeshes.begin(); it != allMDMeshes.end(); it++) {
    VsMDMesh* meshMeta = it->second;
apletzer's avatar
apletzer committed
511 512 513 514
    for (size_t i = 0; i < meshMeta->getNumBlocks(); i++) {
      if (meshMeta->getBlock(i)->getFullName() == name) {
        VsLog::debugLog() << "VsReader::findSubordinateMDMesh(" <<name <<"): Returning result." << std::endl;
        return meshMeta->getBlock(i);
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
      }
    }
  }
  VsLog::debugLog() << "VsMDMesh::findSubordinateMDMesh(" <<name <<"): Returning NULL." << std::endl;
  return NULL;
}

void VsRegistry::buildMDMeshes() {
  VsLog::debugLog() <<"VsRegistry::buildMDMeshes() - Entering." <<std::endl;
  
  // Go through list of all meshes and group the MD meshes together
  std::map<std::string, VsMesh*>::const_iterator it;
  for (it = allMeshes.begin(); it != allMeshes.end(); it++) {
    VsLog::debugLog() <<"VsRegistry::buildMDMeshes() - examining mesh " <<(*it).first <<std::endl;
    VsMesh* mesh = (*it).second;
    if (!mesh) {
      VsLog::errorLog() <<"VsRegistry::buildMDMeshes() - mesh is NULL?" <<std::endl;
      continue;
    }
apletzer's avatar
apletzer committed
534
    VsAttribute* mdMeshNameAttribute = mesh->getAttribute(VsSchema::mdAtt);
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
    std::string mdMeshName = "";
    if (mdMeshNameAttribute) {
      mdMeshNameAttribute->getStringValue(&mdMeshName);
    }
    if (!mdMeshName.empty()) {
      VsMDMesh* mdMesh = getMDMesh(mdMeshName);
      
      //If this is a new md mesh, create it
      if (mdMesh == NULL) {
        VsLog::debugLog() <<"VsRegistry::buildMDMeshes() - MD mesh not found with name " <<mdMeshName <<".  Creating." <<std::endl;
        mdMesh = new VsMDMesh(mesh, mdMeshName);
      }
      
      //add this group to the md mesh
      bool success = mdMesh->addBlock(mesh);
      if (!success) {
        VsLog::debugLog() <<"VsRegistry::buildMDMeshes() - failed to add block to md mesh.  Will remain as a stand-alone mesh." <<std::endl;
      }
    }
  }
  
  VsLog::debugLog() <<"VsRegistry::buildMDMeshes() - Exiting." <<std::endl;
}

559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
/*********** TRANSFORMED VARIABLES ****************************/
void VsRegistry::buildTransformedVariables() {
  std::map<std::string, VsVariable*>::const_iterator it;
  for (it = allVariables.begin(); it != allVariables.end(); ++it) {
    VsLog::debugLog() <<"VsRegistry::buildTransformedVariables() - Creating transform names for Variable " <<it->first <<std::endl;
    it->second->createTransformedVariable();
  }

  std::map<std::string, VsVariableWithMesh*>::const_iterator it2;
  for (it2 = allVariablesWithMesh.begin(); it2 != allVariablesWithMesh.end(); ++it2) {
    VsLog::debugLog() <<"VsRegistry::buildTransformedVariables() - Creating transform names for Variable with Mesh " <<it2->first <<std::endl;
    it2->second->createTransformedVariableAndMesh();
  }
}

/*********** TRANSFORMED MESHES *******************************/
void VsRegistry::buildTransformedMeshes() {
  //go through all meshes looking for "vsTransform" flags
  VsLog::debugLog() <<"VsRegistry::buildTransformedMeshes() - Entering." <<std::endl;
  
  // Roopa: Check if there is a transformation specified for this
  // mesh. If so, register the transformed mesh here
  std::map<std::string, VsMesh*>::const_iterator it;
  for (it = allMeshes.begin(); it != allMeshes.end(); it++) {
    VsLog::debugLog() <<"VsRegistry::buildTransformedMeshes() - examining mesh " <<(*it).first <<std::endl;
    VsMesh* mesh = (*it).second;
    if (!mesh) {
      VsLog::errorLog() <<"VsRegistry::buildTransformedMeshes() - mesh is NULL?" <<std::endl;
      continue;
    }
    if (mesh->hasTransform()) {
      std::string transformedMeshName = mesh->getTransformedMeshName();
      VsLog::debugLog() <<"VsRegistry::buildTransformedMeshes() - mesh " <<(*it).first <<" has transformed mesh " <<transformedMeshName <<std::endl;
      registerTransformedMeshName(transformedMeshName, mesh->getFullName());
    }
  }
  
  VsLog::debugLog() <<"VsRegistry::buildTransformedMeshes() - Returning." <<std::endl;
}

/*********** VARIABLES ***********/
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
void VsRegistry::add(VsVariable* variable) {  
  //check for duplicate long name
  VsVariable* foundVariable = this->getVariable(variable->getFullName());
  if (foundVariable) {
    VsLog::errorLog() <<"VsRegistry::add() - Variable already exists with this long name: " <<variable->getFullName() <<std::endl;
    return;
  }
  
  //check for duplicate short names
  foundVariable = this->getVariable(variable->getShortName());
  if (foundVariable) {
    VsLog::warningLog() <<"VsRegistry::add() - Variable already exists with this short name: " <<variable->getShortName() <<std::endl;
  }
  
  allVariables[variable->getFullName()] = variable; 
  allVariablesShort[variable->getShortName()] = variable;
}

int VsRegistry::numVariables() {
  return allVariables.size();
}

void VsRegistry::remove(VsVariable* variable) {
  if (deletingObjects)
    return;

  allVariables.erase(variable->getFullName());
  allVariablesShort.erase(variable->getShortName());
}

630
VsVariable* VsRegistry::getVariable(const std::string& name) {
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  std::string fullName = makeCanonicalName(name);

  std::map<std::string, VsVariable*>::iterator it = allVariables.find(fullName);
  if (it != allVariables.end()) {
    return (*it).second;
  }
  
  it = allVariablesShort.find(fullName);
  if (it != allVariablesShort.end()) {
    return (*it).second;
  }
  return NULL;
}

void VsRegistry::deleteAllVariables() {
  for (std::map<std::string, VsVariable*>::const_iterator it = allVariables.begin();
        it != allVariables.end(); it++) {
      VsVariable* variable = it->second;
      delete(variable);
  }

  allVariables.clear();
  allVariablesShort.clear();
}

apletzer's avatar
apletzer committed
656
void VsRegistry::writeAllVariables() const {
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
  if (allVariables.empty()) {
    VsLog::debugLog() <<"*********** NO VSVARIABLES ********" <<std::endl;
    return;
  }
  
  VsLog::debugLog() <<"********** BEGIN VsVariables *********" <<std::endl;
  
  for (std::map<std::string, VsVariable*>::const_iterator it = allVariables.begin();
        it != allVariables.end(); it++) {
      VsVariable* variable = it->second;
      variable->write();
  }
    
  VsLog::debugLog() <<"********** END VsVariables *********" <<std::endl;
}

void VsRegistry::getAllVariableNames(std::vector<std::string>& names)  {
  std::map<std::string, VsVariable*>::const_iterator it;
  for (it = allVariables.begin(); it != allVariables.end(); ++it)
    names.push_back(it->first);
}


/*********** MD VARIABLES ***************/

682
VsMDVariable* VsRegistry::getMDVariable(const std::string& name) {
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
  // Make name fully qualified
  std::string fullName = makeCanonicalName(name);
  
  std::map<std::string, VsMDVariable*>::iterator it = allMDVariables.find(fullName);
  if (it != allMDVariables.end()) {
   return it->second;
  }
  
  return NULL;
}

void VsRegistry::add(VsMDVariable* var) {  //check for duplicate long name
  VsMDVariable* foundVariable = this->getMDVariable(var->getFullName());
  if (foundVariable) {
    VsLog::errorLog() <<"VsRegistry::add() - MD Variable already exists with this long name: " <<var->getFullName() <<std::endl;
    return;
  }
  
  allMDVariables[var->getFullName()] = var;
}

void VsRegistry::remove(VsMDVariable* var) {
  allMDVariables.erase(var->getFullName());
}

void VsRegistry::getAllMDVariableNames(std::vector<std::string>& names)  {
  std::map<std::string, VsMDVariable*>::const_iterator it;
  for (it = allMDVariables.begin(); it != allMDVariables.end(); ++it)
    names.push_back(it->first);
}

apletzer's avatar
apletzer committed
714
void VsRegistry::writeAllMDVariables() const {
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
  if (allMDVariables.empty()) {
    VsLog::debugLog() <<"*********** NO MDVARIABLES ********" <<std::endl;
    return;
  }
  
  VsLog::debugLog() <<"*********** BEGIN MDVARIABLES ********" <<std::endl;
  std::map<std::string, VsMDVariable*>::const_iterator it;
  for (it = allMDVariables.begin(); it != allMDVariables.end(); ++it) {
    it->second->write();
  }
  
  VsLog::debugLog() <<"*********** END MDVARIABLES ********" <<std::endl;
}

int VsRegistry::numMDVariables() {
  return allMDVariables.size();
}

void VsRegistry::buildMDVars() {
  VsLog::debugLog() <<"VsRegistry::buildMDVars() - Entering." <<std::endl;
  
  // Go through list of all vars and group the MD vars together
  std::map<std::string, VsVariable*>::const_iterator it;
  for (it = allVariables.begin(); it != allVariables.end(); it++) {
    VsVariable* var = (*it).second;
    
apletzer's avatar
apletzer committed
741
    VsAttribute* mdVarAtt = var->getAttribute(VsSchema::mdAtt);
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
    if (!mdVarAtt) {
      continue;
    }
    
    std::string mdVarName;
    mdVarAtt->getStringValue(&mdVarName);
    
    if (!mdVarName.empty()) {
      VsMDVariable* mdVar = getMDVariable(mdVarName);
      if (!mdVar) {
        VsLog::debugLog() <<"VsRegistry::buildMDVars() - MD variable " + mdVarName + " not found, creating." <<std::endl;
        
        //the md var lives on an md mesh, so cross-reference to get the md mesh
        VsMDMesh* mdMesh = getMDParentForMesh(var->getMeshName());
        
        //did we find the appropriate md mesh?
        if (!mdMesh) {
          VsLog::debugLog() <<"VsRegistry::buildMDVars() - WARNING: variable " + var->getFullName() + " is declared as part of MD Var " + mdVarName + " but referenced mesh " + var->getMeshName() + " is not part of an MD mesh." <<std::endl;
          continue;
        } else {
          //note that the MD variable inherits index order and centering of first block
          mdVar = new VsMDVariable(var, mdMesh, mdVarName);
          
          VsLog::debugLog() <<"VsRegistry::buildMDVars() - Created new MD Variable named " << mdVarName <<" on mesh " <<mdMesh->getFullName() <<std::endl;
        }
      }

      if (!mdVar) {
        VsLog::debugLog() <<"VsRegistry::buildMDVars() - MD var object doesn't exist?" <<std::endl;
        continue;
      }
      //Finally, add the var to the MD var
      bool success = mdVar->addBlock(var);
      if (!success) {
        VsLog::warningLog() <<"VsRegistry::buildMDVars() - unable to add var to MD var, will remain stand-alone" <<std::endl;
      }
    }
  }
  VsLog::debugLog() <<"VsRegistry::buildMDVars() - Returning." <<std::endl;
}

VsVariable* VsRegistry::findSubordinateMDVar(const std::string& name) {
 VsLog::debugLog() << "VsRegistry::findSubordinateMDVar(" <<name <<"): Entering." << std::endl;
 for (std::map<std::string, VsMDVariable*>::const_iterator it = allMDVariables.begin(); it != allMDVariables.end(); it++) {
   VsMDVariable* varMeta = it->second;
apletzer's avatar
apletzer committed
787 788
   for (unsigned int i = 0; i < varMeta->getNumBlocks(); i++) {
     if (varMeta->getBlock(i)->getFullName() == name) {
789
       VsLog::debugLog() << "VsRegistry::findSubordinateMDVar(" <<name <<"): Returning result." << std::endl;
apletzer's avatar
apletzer committed
790
       return varMeta->getBlock(i);
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
     }
   }
 }
 VsLog::debugLog() << "VsRegistry::findSubordinateMDVar(" <<name <<"): Returning NULL." << std::endl;
 return NULL;
}

/*********** VARIBLES WITH MESH ***********/
void VsRegistry::add(VsVariableWithMesh* variable) {
  //check for duplicate long name
  VsVariableWithMesh* foundVariable = this->getVariableWithMesh(variable->getFullName());
  if (foundVariable) {
    VsLog::errorLog() <<"VsRegistry::add() - Variable with mesh already exists with this full name: " <<variable->getFullName() <<std::endl;
    return;
  }
  
  //check for duplicate short names
  foundVariable = this->getVariableWithMesh(variable->getShortName());
  if (foundVariable) {
    VsLog::errorLog() <<"VsRegistry::add() - Variable with mesh already exists with this short name: " <<variable->getShortName() <<std::endl;
  }
  
  allVariablesWithMesh[variable->getFullName()] = variable; 
  allVariablesWithMeshShort[variable->getShortName()] = variable;
}

int VsRegistry::numVariablesWithMesh() {
  return allVariablesWithMesh.size();
}

void VsRegistry::remove(VsVariableWithMesh* variable) {  
  if (deletingObjects)
    return;

  allVariablesWithMesh.erase(variable->getFullName());
  allVariablesWithMeshShort.erase(variable->getShortName());
}

829
VsVariableWithMesh* VsRegistry::getVariableWithMesh(const std::string& name) {
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
  std::string fullName = makeCanonicalName(name);

  std::map<std::string, VsVariableWithMesh*>::iterator it = allVariablesWithMesh.find(fullName);
  if (it != allVariablesWithMesh.end()) {
    return (*it).second;
  }
  
  it = allVariablesWithMeshShort.find(fullName);
  if (it != allVariablesWithMeshShort.end()) {
    return (*it).second;
  }
  return NULL;
}

void VsRegistry::deleteAllVariablesWithMesh() {
  for (std::map<std::string, VsVariableWithMesh*>::const_iterator it = allVariablesWithMesh.begin();
        it != allVariablesWithMesh.end(); it++) {
      VsVariableWithMesh* variable = it->second;
      delete (variable);
  }
  
  allVariablesWithMesh.clear();
  allVariablesWithMeshShort.clear();
}

apletzer's avatar
apletzer committed
855
void VsRegistry::writeAllVariablesWithMesh() const {
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
  if (allVariablesWithMesh.empty()) {
    VsLog::debugLog() <<"********** NO VsVariablesWithMesh *********" <<std::endl;
    return;
  }
  
  VsLog::debugLog() <<"********** BEGIN VsVariablesWithMesh *********" <<std::endl;
  
  for (std::map<std::string, VsVariableWithMesh*>::const_iterator it = allVariablesWithMesh.begin();
        it != allVariablesWithMesh.end(); it++) {
      VsVariableWithMesh* variable = it->second;
      variable->write();
  }
    
  VsLog::debugLog() <<"********** END VsVariablesWithMesh *********" <<std::endl;
}

void VsRegistry::getAllVariableWithMeshNames(std::vector<std::string>& names)  {
  std::map<std::string, VsVariableWithMesh*>::const_iterator it;
  for (it = allVariablesWithMesh.begin(); it != allVariablesWithMesh.end(); ++it)
    names.push_back(it->first);
}

878 879 880 881 882 883 884 885 886 887 888
/********************* TRANSFORMED MESH NAMES ************************/
bool VsRegistry::registerTransformedMeshName(std::string transformedName, std::string origName) {
  //first, look for a match and report failure if the name is already registered
  std::string oName = getOriginalMeshName(transformedName);
  if (!oName.empty()) {
    if (origName != oName) {
      VsLog::debugLog() << "ERROR VsRegistry::registerTransformedMeshName() - " 
                        << transformedName << " is already registered to " 
                        << oName << std::endl;
      return false;
    } else {
889
      VsLog::debugLog() << "VsRegistry::registerTransformedMeshName() - received duplicate registration for " 
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
                        << origName << std::endl;
      VsLog::debugLog() << "VsRegistry::registerTransformedMeshName() - but all info matches, so it should be ok"
                        << std::endl;
      return true;
    }
  }

  // Ok, register the new name mapping
  transformedMeshNames[transformedName] = origName;
  VsLog::debugLog() << "VsRegistry::registerTransformedMeshName(" 
                    << transformedName << ", " << transformedMeshNames[transformedName]  
                    << ") - registration succeeded." << std::endl;
  return true;
}

std::string VsRegistry::getOriginalMeshName(std::string transformedMeshName) {
  // return the value if the name is registered
  return transformedMeshNames[transformedMeshName];
}

/******************* TRANSFORMED VARS *******************/
bool VsRegistry::registerTransformedVarName(std::string transformedName, std::string origName) {
  //first, look for a match and report failure if the name is already registered
  std::string oName = getOriginalVarName(transformedName);
  if (!oName.empty()) {
    if (origName != oName) {
      VsLog::debugLog() << "ERROR VsRegistry::registerTransformedVarName() - "
                        << transformedName << " is already registered to "
                        << oName << std::endl;
      return false;
    } else {
      VsLog::debugLog() << "VsRegistry::registerTransformedVarName() - received duplicate registration for "
                        << origName << std::endl;
      VsLog::debugLog() << "VsRegistry::registerTransformedVarName() - but all info matches, so it should be ok"
                        << std::endl;
      return true;
    }
  }

  // Ok, register the new name mapping
  transformedVarNames[transformedName] = origName;
  VsLog::debugLog() << "VsRegistry::registerTransformedVarName("
                    << transformedName << ", " << transformedVarNames[transformedName]
                    << ") - registration succeeded." << std::endl;
  return true;
}

std::string VsRegistry::getOriginalVarName(std::string transformedVarName) {
  // return the value if the name is registered
  return transformedVarNames[transformedVarName];
}

942
/******************* EXPRESSIONS ************************/
943 944
void VsRegistry::addExpression(const std::string& name, 
                               const std::string& value) {
945 946 947 948 949 950 951 952 953 954 955 956
  //check for duplicates
  std::map<std::string, std::string>::const_iterator it;
  it = allExpressions.find(name);
  if (it != allExpressions.end()) {
    VsLog::errorLog() <<"VsRegistry::addExpression(" <<name <<", " <<value <<") - Duplicate name!  Rejecting expression." <<std::endl;
    return;
  }

  allExpressions[name] = value;
}

/**
957
 * VsRegistry::buildExpressions()
958 959 960 961 962 963
 * 
 * A "VsVars" group represents a set of names and values
 * Each attribute in the group represents one expression
 * The name of the attribute is the name of the expression
 * The value of the attribute is the value of the expression
 */
apletzer's avatar
apletzer committed
964
void VsRegistry::buildExpressions(VsGroup* group) {
965 966 967 968 969
  if (!group) {
    return;
  }
  VsLog::debugLog() <<"VsRegistry::buildExpressions() - Entering with group " <<group->getFullName() <<std::endl;
  
apletzer's avatar
apletzer committed
970 971 972
  std::map<std::string, VsAttribute*>::const_iterator k;
  for (k = group->getAllAttributes().begin(); k != group->getAllAttributes().end(); ++k) {
    VsAttribute* att = (*k).second;
973 974
    if (att->getShortName() != VsSchema::typeAtt) {
      std::string s;
apletzer's avatar
apletzer committed
975
      int err = att->getStringValue(&s);
976 977 978 979 980 981 982 983
      if (err == 0) {
        addExpression(att->getShortName(), s);
      }
    }
  }
  VsLog::debugLog() <<"VsRegistry::buildExpressions() exiting." <<std::endl;
}

apletzer's avatar
apletzer committed
984
void VsRegistry::writeAllExpressions() const {
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
  if (allExpressions.empty()) {
    VsLog::debugLog() <<"******** No Expressions *********" <<std::endl;
    return;
  }

  VsLog::debugLog() <<"******** BEGIN Expressions *********" <<std::endl;
  std::map<std::string, std::string>::const_iterator it;
  for (it = allExpressions.begin(); it != allExpressions.end(); it++) {
    VsLog::debugLog() <<"(" <<(*it).first <<", " <<(*it).second <<")" <<std::endl;
  }

  VsLog::debugLog() <<"******** END Expressions *********" <<std::endl;
}

std::map<std::string, std::string>* VsRegistry::getAllExpressions() {
  return &allExpressions;
}

1003 1004 1005
int VsRegistry::numExpressions() {
  return allExpressions.size();
}
1006

1007
void VsRegistry::createComponents() {
1008 1009 1010 1011 1012
  VsLog::debugLog() <<"VsRegistry::createComponents() - Entering" <<std::endl;
  
  std::map<std::string, VsMDVariable*>::const_iterator it;
  for (it = allMDVariables.begin(); it != allMDVariables.end(); ++it) {
    VsLog::debugLog() <<"VsRegistry::createComponents() - Creating components for MD Variable " <<it->first <<std::endl;
1013
    it->second->createComponents();
1014 1015 1016 1017 1018
  }

  std::map<std::string, VsVariable*>::const_iterator it2;
  for (it2 = allVariables.begin(); it2 != allVariables.end(); ++it2) {
    VsLog::debugLog() <<"VsRegistry::createComponents() - Creating components for Variable " <<it2->first <<std::endl;
1019
    it2->second->createComponents();
1020 1021 1022 1023
  }

  std::map<std::string, VsVariableWithMesh*>::const_iterator it3;
  for (it3 = allVariablesWithMesh.begin(); it3 != allVariablesWithMesh.end(); ++it3) {
1024
    VsLog::debugLog() <<"VsRegistry::createComponents() - Creating components for Variable With Mesh " <<it3->first <<std::endl;
1025 1026 1027 1028 1029 1030
    it3->second->createComponents();
  }
  
  VsLog::debugLog() <<"VsRegistry::createComponents() - Returning." <<std::endl;
}
  
1031 1032 1033
void VsRegistry::registerComponent(const std::string& varName, 
                                   int componentNumber, 
                                   const std::string& userSuppliedName) {
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
  
  //If the user supplied a name, try to use it
  if (!userSuppliedName.empty()) {
    registerComponentInfo(userSuppliedName, varName, componentNumber);
  }
  
  //for backwards compatibility, register the "old-style" name too                                                                      
  std::string oldStyleName = getOldComponentName(varName, componentNumber);
  if (oldStyleName != userSuppliedName) {
    registerComponentInfo(oldStyleName, varName, componentNumber);
  }
}

1047 1048 1049
bool VsRegistry::registerComponentInfo(const std::string& componentName, 
                                       const std::string& varName, 
                                       int componentNumber) {
1050 1051 1052 1053 1054 1055 1056 1057 1058
  //yes, I should use a std::hash_map for this
  
  //first, look for a match and report failure if the name is already registered
  NamePair foundPair;
  getComponentInfo(componentName, &foundPair);
  if (!foundPair.first.empty()) {
    std::string temp = foundPair.first;
    int tempIndex = foundPair.second;
    if ((varName != temp) || (componentNumber != tempIndex)) {
apletzer's avatar
apletzer committed
1059
      VsLog::debugLog() <<"ERROR VsReader::registerComponentInfo() - " <<componentName <<" is already registered to component " <<temp <<" index " <<tempIndex <<std::endl;
1060 1061
      return false;
    } else {
apletzer's avatar
apletzer committed
1062 1063
      VsLog::debugLog() <<"VsReader::registerComponentInfo() - received duplicate registration for " <<varName <<" and index " <<componentNumber <<std::endl;
      VsLog::debugLog() <<"VsReader::registerComponentInfo() - but all info matches, so it should be ok" <<std::endl;
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
      return true;
    }
  }
  
  //Ok, register the new name mapping
  std::pair<std::string, int> innerPair;
  innerPair.first = varName;
  innerPair.second = componentNumber;
  std::pair<std::string, std::pair<std::string, int> > newPair;
  newPair.first = componentName;
  newPair.second = innerPair;
  componentNames.push_back(newPair);
  //VsLog::debugLog() <<"newpair.first = " <<newPair.first <<std::endl;
  //VsLog::debugLog() <<"newpair.second.first = " <<newPair.second.first <<std::endl;
  //VsLog::debugLog() <<"newpair.second.second = " <<newPair.second.second <<std::endl;
  
apletzer's avatar
apletzer committed
1080
  VsLog::debugLog() <<"VsReader::registerComponentInfo(" <<componentName <<", " <<varName <<", " <<componentNumber <<") - registration succeeded." <<std::endl;
1081 1082 1083
  return true;
}

1084 1085
void VsRegistry::getComponentInfo(const std::string& componentName, 
                                  NamePair* namePair) {
1086 1087 1088 1089 1090 1091
  //yes, I should use a std::hash_map for this
  
  //look for a match and return the value if the name is registered
  for (unsigned int i = 0; i < componentNames.size(); i++) {
    std::pair<std::string, NamePair > foundPair = componentNames[i];
    if (foundPair.first == componentName) {
apletzer's avatar
apletzer committed
1092
      VsLog::debugLog() <<"VsReader::getComponentInfo(" <<componentName <<") - Found registered name, returning. " <<std::endl;
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
      namePair->first = foundPair.second.first;
      namePair->second = foundPair.second.second;
      return;
    }
  }
  
  namePair->first = "";
  namePair->second = -1;
}

1103 1104
std::string VsRegistry::getComponentName(const std::string& varName, 
                                         int componentNumber) {
1105 1106 1107 1108
  for (unsigned int i = 0; i < componentNames.size(); i++) {
    std::pair<std::string, NamePair > foundPair = componentNames[i];
    NamePair tempNamePair = foundPair.second;
    if ((tempNamePair.first == varName) && (tempNamePair.second == componentNumber)) {
apletzer's avatar
apletzer committed
1109
      VsLog::debugLog() <<"VsReader::getComponentInfo(" <<varName <<", " <<componentNumber <<") - Found matching name & index, returning. " <<std::endl;
1110 1111 1112 1113
      return foundPair.first;
    }
  }

apletzer's avatar
apletzer committed
1114
  VsLog::debugLog() <<"VsReader::getComponentInfo(" <<varName <<", " <<componentNumber <<") - no match found." <<std::endl;
1115 1116 1117
  return "";
}

1118 1119
void VsRegistry::getComponentInfo(const std::string& varName, 
                                  int componentNumber, NamePair* namePair) {
1120 1121 1122 1123 1124 1125 1126 1127
  //yes, I should use a std::hash_map for this
  
  NamePair tempNamePair;
  //look for a match and return the value if the name is registered
  for (unsigned int i = 0; i < componentNames.size(); i++) {
    std::pair<std::string, NamePair > foundPair = componentNames[i];
    tempNamePair = foundPair.second;
    if ((tempNamePair.first == varName) && (tempNamePair.second == componentNumber)) {
apletzer's avatar
apletzer committed
1128
      VsLog::debugLog() <<"VsReader::getComponentInfo(" <<varName <<", " <<componentNumber <<") - Found matching name & index, returning. " <<std::endl;
1129 1130 1131 1132 1133 1134
      namePair->first = tempNamePair.first;
      namePair->second = tempNamePair.second;
      return;
    }
  }
  
apletzer's avatar
apletzer committed
1135
  VsLog::debugLog() <<"VsReader::getComponentInfo(" <<varName <<", " <<componentNumber <<") - no match found." <<std::endl;
1136 1137 1138 1139 1140
  
  namePair->first = "";
  namePair->second = -1;
}

1141 1142
std::string VsRegistry::getOldComponentName(const std::string& varName, 
                                            int componentIndex) {
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
  //generates an old-style name for the component
  //of the form "varName_index"
  
  std::string compName = varName;
  std::stringstream ss;
  ss << componentIndex;
  compName.append("_");
  compName.append(ss.str());
  
  return compName;
}