VsRegistry.h 5.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/**
 * @file VsRegistry.h
 * 
 * @class VsRegistry
 * @brief Tracks all objects created while reading a file.
 * 
 * Maintains lists of all objects that are
 * needed to represent an hdf5 file.  Provides functions
 * to retrieve objects by name, print debugging information,
 * and get lists of object names.  Also provides for the creation
 * of MDVariables and MDMeshes from the lists of variables and meshes.
 *
 *  Created on: Apr 30, 2010
 *      Author: mdurant
 */

#ifndef VSREGISTRY_H_
#define VSREGISTRY_H_

apletzer's avatar
apletzer committed
20 21
class VsDataset;
class VsGroup;
22 23 24 25 26 27 28 29 30 31
class VsMesh;
class VsVariableWithMesh;
class VsVariable;
class VsMDMesh;
class VsMDVariable;

#include <map>
#include <string>
#include <vector>

32
typedef std::pair<std::string, int> NamePair;
33 34 35 36 37 38 39 40

class VsRegistry {
public:
  VsRegistry();
  virtual ~VsRegistry();
  void deleteAllObjects();
  
  //DATASETS
apletzer's avatar
apletzer committed
41 42 43
  void add(VsDataset* obj);
  void remove(VsDataset* obj);
  VsDataset* getDataset(const std::string& name);
44
  void deleteAllDatasets();
apletzer's avatar
apletzer committed
45
  void writeAllDatasets() const;
46 47 48 49
  int numDatasets();
  void buildDatasetObjects();
 
  //GROUPS
apletzer's avatar
apletzer committed
50 51 52
  void add(VsGroup* obj);
  void remove(VsGroup* obj);
  VsGroup* getGroup(const std::string& name);
53
  void deleteAllGroups();
apletzer's avatar
apletzer committed
54
  void writeAllGroups() const;
55 56
  int numGroups();
  void buildGroupObjects();
apletzer's avatar
apletzer committed
57 58
  void loadTime(VsGroup* group);
  void loadRunInfo(VsGroup* group);
59 60 61 62
  
  //MESHES
  void add(VsMesh* mesh);
  void remove(VsMesh* mesh);
63
  VsMesh* getMesh(const std::string& name);
64 65
  void getAllMeshNames(std::vector<std::string>& names);
  void deleteAllMeshes();
apletzer's avatar
apletzer committed
66
  void writeAllMeshes() const;  
67 68 69 70 71 72
  int numMeshes();
  
  //MD MESHES
  void add(VsMDMesh* var);
  void remove(VsMDMesh* var);
  void buildMDMeshes();
apletzer's avatar
apletzer committed
73
  void writeAllMDMeshes() const;
74
  VsMDMesh* getMDMesh(const std::string& name);
75 76 77 78 79 80
  VsMDMesh* getMDParentForMesh(const std::string& name);
  VsMesh* findSubordinateMDMesh(const std::string& name);
  void getAllMDMeshNames(std::vector<std::string>& names);
  int numMDMeshes();
  
  //VARIABLES
81 82 83
  void add(VsVariable* variable);
  void remove(VsVariable* variable);
  VsVariable* getVariable(const std::string& name);
84 85
  void getAllVariableNames(std::vector<std::string>& names);
  void deleteAllVariables();
apletzer's avatar
apletzer committed
86
  void writeAllVariables() const;  
87 88 89
  int numVariables();

  //VARIABLES WITH MESH
90 91 92
  void add(VsVariableWithMesh* variable);
  void remove(VsVariableWithMesh* variable);
  VsVariableWithMesh* getVariableWithMesh(const std::string& name);
93 94
  void getAllVariableWithMeshNames(std::vector<std::string>& names);
  void deleteAllVariablesWithMesh();
apletzer's avatar
apletzer committed
95
  void writeAllVariablesWithMesh() const;  
96
  int numVariablesWithMesh();
97 98 99 100 101 102 103 104 105

  // TRANSFORMED MESH NAMES
  bool registerTransformedMeshName(std::string transformedMeshName, std::string origMeshName);
  std::string getOriginalMeshName(std::string transformedMeshName);

  // TRANSFORMED VAR NAMES
  bool registerTransformedVarName(std::string transformedVarName, std::string origVarName);
  std::string getOriginalVarName(std::string transformedVarName);

106 107 108 109
  //MD VARIABLES
  void add(VsMDVariable* var);
  void remove(VsMDVariable* var);
  void buildMDVars();
apletzer's avatar
apletzer committed
110
  void writeAllMDVariables() const;
111
  VsMDVariable* getMDVariable(const std::string& name);
112 113 114 115
  void getAllMDVariableNames(std::vector<std::string>& names);
  int numMDVariables();
  VsVariable* findSubordinateMDVar(const std::string& name);
  
116 117 118 119
  //Transformed meshes
  void buildTransformedMeshes();
  void buildTransformedVariables();
  
120
  //VsVars
apletzer's avatar
apletzer committed
121
  void buildExpressions(VsGroup* group);
122
  void addExpression(const std::string& name, const std::string& value);
apletzer's avatar
apletzer committed
123
  void writeAllExpressions() const;
124
  std::map<std::string, std::string>* getAllExpressions();
125
  int numExpressions();
126 127

  //Variable components
128 129 130 131 132 133 134 135 136 137 138
  void getComponentInfo(const std::string& componentName, 
                        NamePair* namePair);
  void getComponentInfo(const std::string& varName, 
                        int componentNumber, NamePair* namePair);
  std::string getComponentName(const std::string& varName, 
                               int componentNumber);
  std::string getOldComponentName(const std::string& varName, 
                                  int componentIndex);
  void registerComponent(const std::string& varName, 
                         int componentNumber, 
                         const std::string& userSuppliedName);
139
  void createComponents();
140 141 142 143

  //Time
  bool hasTime() { return (timeValue != -1); }
  double getTime() { return timeValue; }
144 145
  bool hasCycle() { return (cycle != -1); }
  double getCycle() { return cycle; }
146 147 148 149 150 151 152
    
private:
  /**
   * A boolean flag for when objects are being deleted.
   */
  bool deletingObjects;
  
apletzer's avatar
apletzer committed
153 154
  std::map<std::string, VsDataset*> allDatasets;
  std::map<std::string, VsDataset*> allDatasetsShort;
155

apletzer's avatar
apletzer committed
156 157
  std::map<std::string, VsGroup*> allGroups;
  std::map<std::string, VsGroup*> allGroupsShort;
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

  std::map<std::string, VsMesh*> allMeshes;
  std::map<std::string, VsMesh*> allMeshesShort;

  std::map<std::string, VsMDMesh*> allMDMeshes;

  std::map<std::string, VsVariable*> allVariables;
  std::map<std::string, VsVariable*> allVariablesShort;

  std::map<std::string, VsMDVariable*> allMDVariables;
  
  std::map<std::string, VsVariableWithMesh*> allVariablesWithMesh;
  std::map<std::string, VsVariableWithMesh*> allVariablesWithMeshShort;

  std::map<std::string, std::string> allExpressions;
  
174 175 176
  std::map<std::string, std::string> transformedMeshNames;
  std::map<std::string, std::string> transformedVarNames;

177 178 179 180
  //tracks whether time data has been read for this database
  // a value of -1 indicates no time data is available
  //Named timeValue because "time" is a typedef
  double timeValue;
181
  int cycle;
182 183 184 185 186
  
  // a registry of user-specified component names and their mappings
  // first element of pair is the user-specified name
  // second element of pair is "true" component name
  std::vector< std::pair<std::string, NamePair > > componentNames;
187 188 189 190

  bool registerComponentInfo(const std::string& componentName, 
                             const std::string& varName, 
                             int componentNumber);
191 192 193 194

};

#endif /* VSREGISTRY_H_ */