Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Xabsl2/GT/GTXabsl2Profiler/GTXabsl2ProfilerNameTable.cpp

Go to the documentation of this file.

    00001 #include "GTXabsl2ProfilerNameTable.h"
    00002 void GTXabsl2ProfilerNameTable::init(Xabsl2Engine& engine){
    00003   maxDepth = 0;
    00004   registerOption(engine.getRootOption(), 0);
    00005   countDepth(engine.getRootOption(), 0);
    00006 }
    00007
    00008 int GTXabsl2ProfilerNameTable::find(const std::string optionName, const std::string state) const
    00009 {
    00010   for(unsigned i = 0; i < this->size(); ++i){
    00011     if((*this)[i].optionName  == optionName){
    00012       for(unsigned j = 0; j < (*this)[i].states.size();++j)
    00013       {
    00014         if((*this)[i].states[j] == state)
    00015           return int(i);
    00016       }
    00017
    00018     }
    00019   }
    00020   return -1;
    00021 }
    00022
    00023 int GTXabsl2ProfilerNameTable::findState(const std::string optionName, const std::string state) const
    00024 {
    00025   for(unsigned i = 0; i < this->size(); ++i){
    00026
    00027     if((*this)[i].optionName  == optionName){
    00028       for(unsigned j = 0; j < (*this)[i].states.size(); ++j){
    00029         if(state == (*this)[i].states[j])
    00030           return int(j);
    00031       }
    00032
    00033     }
    00034   }
    00035   return -1;
    00036 }
    00037
    00038 int GTXabsl2ProfilerNameTable::findOption(const std::string optionName) const
    00039 {
    00040   for(unsigned i = 0; i < this->size(); ++i)
    00041     if((*this)[i].optionName  == optionName)
    00042       return int(i);
    00043   return -1;
    00044 }
    00045
    00046
    00047 void GTXabsl2ProfilerNameTable::registerOption(const Xabsl2Option* option, int depth){
    00048   std::vector<std::string> states;
    00049
    00050   int i;
    00051   for(i = 0; i<option->states.getSize();++i){
    00052     if(!exists( option->n, option->states[i]->n))
    00053       states.push_back(option->states.getName(i));
    00054   }
    00055
    00056   std::vector<std::string> params;
    00057   for(i = 0; i<option->parameters.getSize();++i){
    00058       params.push_back(option->parameters.getName(i));
    00059   }
    00060
    00061
    00062   this->push_back(GTXabsl2ProfilerNameTableEntry(option->n, states, params, depth));
    00063
    00064   for(int j=0; j<option->states.getSize();++j){
    00065     if(option->states[j]->subsequentOption && !existsOption(option->states[j]->subsequentOption->n)){
    00066       registerOption(option->states[j]->subsequentOption, depth+1);
    00067     }
    00068   }
    00069 }
    00070
    00071 void GTXabsl2ProfilerNameTable::countDepth(const Xabsl2Option* option, int depth){
    00072   if(depth > maxDepth)
    00073     maxDepth = depth;
    00074   for(int i=0; i< option->states.getSize();++i){
    00075     if( (*this)[getOptionPosition(option->n)].maxDepth < depth)
    00076       (*this)[getOptionPosition(option->n)].maxDepth = depth;
    00077   }
    00078   for(int j=0; j<option->states.getSize();++j){
    00079     if(option->states[j]->subsequentOption)
    00080       countDepth(option->states[j]->subsequentOption, depth+1);
    00081   }
    00082
    00083 }
    00084
    00085 In& operator>>(In& in, GTXabsl2ProfilerNameTable& nameTable)
    00086 {
    00087
    00088     // nametable
    00089   int nametablesize;
    00090   char optionname[300];
    00091   char name[300];
    00092   int depth;
    00093   in >> nametablesize;
    00094   for(;nametablesize > 0; --nametablesize){
    00095     std::vector<std::string> statenames;
    00096     std::vector<std::string> paramnames;
    00097
    00098     in >> optionname;
    00099     in >> depth;
    00100
    00101     int number;
    00102     in >> number;
    00103     for(;number > 0; --number){
    00104       in >> name;
    00105       statenames.push_back(name);
    00106     }
    00107     in >> number;
    00108     for(;number > 0; --number){
    00109       in >> name;
    00110       paramnames.push_back(name);
    00111     }
    00112
    00113     nameTable.push_back(GTXabsl2ProfilerNameTableEntry(optionname, statenames, paramnames, depth));
    00114     if(depth > nameTable.maxDepth - 1)
    00115       nameTable.maxDepth = depth + 1;
    00116   }
    00117   return in;
    00118 }
    00119
    00120 Out& operator<<(Out& out, const GTXabsl2ProfilerNameTable& nameTable)
    00121 {
    00122   out << nameTable.size();
    00123   if(nameTable.size()){
    00124
    00125     for(unsigned i = 0; i < nameTable.size(); ++i){
    00126
    00127       out << nameTable[i].optionName.c_str();
    00128       out << nameTable[i].maxDepth;
    00129       out << nameTable[i].states.size();
    00130
    00131       int j;
    00132       for(j = 0; j < (int)nameTable[i].states.size(); ++j){
    00133         out << nameTable[i].states[j].c_str();
    00134       }
    00135
    00136       out << nameTable[i].parameters.size();
    00137       for(j = 0; j < (int)nameTable[i].parameters.size(); ++j){
    00138         out << nameTable[i].parameters[j].c_str();
    00139       }
    00140     }
    00141   }
    00142   return out;
    00143 }