MetriVis Overview | Download | User Manual | Development
Reference Overview | Design Documentation | Reference Backend | Reference Frontend

src/container/MultiType.h

Go to the documentation of this file.
00001 /*
00002  *   MetriVis - Metrics Visualization Application
00003  *
00004  *
00005  *   License notice:
00006  *
00007  *   This program is free software: you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation, either version 3 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  */
00021 
00022 
00029 #ifndef _METRIVIS_MULTI_TYPE_H
00030 #define _METRIVIS_MULTI_TYPE_H
00031 
00032 
00033 #include <string>
00034 #include <vector>
00035 #include <boost/shared_ptr.hpp>
00036 
00037 
00038 namespace metrivis {
00039 
00040 
00042 typedef enum {
00043   MT_NULL            = 0,                  
00044   MT_STRING          = 1,                  
00045   MT_DOUBLE_1D_ARRAY = 2,                  
00046   MT_DOUBLE_2D_ARRAY = 3,                  
00047   MT_STRING_2D_ARRAY = 4,                  
00048 } MT_Type;
00049 
00050 
00057 class MultiType {
00058 
00059 public:
00067   MultiType(MT_Type type = MT_NULL);
00068 
00069 
00073   ~MultiType();
00074 
00075 
00079   MultiType& operator=(std::string value) {
00080     this->SetString(value);
00081     return *this;
00082   };
00083 
00084 
00091   long double GetDoubleElement(long index_x);
00092   long double* GetDoubleElements(long index_x);
00093   long double GetDoubleElement(long index_x, long index_y);
00094 
00102   const std::string& GetStringElement(long index_x, long index_y);
00103 
00104 
00109   void SetString(const std::string& value);
00110 
00115   void AppendString(const std::string& value);
00116 
00117 
00126   void SetDoubleArray(long double* double_array, long length);
00127 
00128 
00138   void SetDoubleArray(long double** double_array, long length_x, long length_y);
00139 
00140 
00146   void PushString(long array_index, const std::string& element);
00147 
00148 
00152   std::string GetString() const;
00153 
00154 
00159   long GetSize() const;
00160 
00161 
00166   long length_x() const {
00167     if( value_.type == MT_DOUBLE_2D_ARRAY) {
00168       return value_.length_x;
00169     }
00170 
00171     return value_.string_array.size();
00172   }
00173 
00174 
00179   long length_y() const {
00180     if( value_.type == MT_DOUBLE_2D_ARRAY)
00181       return value_.length_y;
00182     else if( value_.type == MT_STRING_2D_ARRAY) {
00183       if( value_.string_array.size() > 0) {
00184         return value_.string_array[0].size();
00185       }
00186     }
00187 
00188     return 0;
00189   }
00190 
00191 
00192 private:
00193 
00197   MultiType(const MultiType& mt);
00198 
00199 
00200 private:
00201 
00207   struct Value {
00208     std::string String;               
00209     long double* double_1D_array;          
00210     long double** double_2D_array;         
00211     long length_x;                    
00212     long length_y;                    
00213 
00214     std::vector<std::vector<std::string> > string_array; 
00215 
00216     MT_Type type;                     
00217   };
00218 
00219   Value value_;                       
00220 };
00221 
00222 
00226 typedef boost::shared_ptr<MultiType> MultiTypePtr;
00227 
00228 } // namespace metrivis
00229 
00230 #endif // _METRIVIS_MULTI_TYPE_H

Generated on Fri Feb 29 16:47:19 2008 for MetriVis by  doxygen 1.5.3