My Project
|
00001 /* 00002 $Id: UInt4Container.hh 2247 2011-04-27 05:20:41Z jisuzuki $ 00003 */ 00004 00005 00006 #ifndef UINT4CONTAINER 00007 #define UINT4CONTAINER 00008 00009 #include <boost/serialization/serialization.hpp> 00010 #include <boost/serialization/string.hpp> 00011 #include <napi.h> 00012 00013 #include "Header.hh" 00014 #include "HeaderBase.hh" 00015 #include "CppToPython.hh" 00016 #include "SplitString.hh" 00017 #include "ElementContainer.hh" 00018 00020 00024 class UInt4Container 00025 { 00026 private: 00027 vector< vector< UInt4 >* > v; 00028 vector< string > s; 00029 vector< vector< Double >* > vd; 00030 vector< string > sd; 00031 00032 HeaderBase *header; 00033 CppToPython *PythonConverter; 00034 void SetupPythonConverter(); 00035 00036 friend class boost::serialization::access; 00040 template <class Archive> 00041 void serialize(Archive &ar, const unsigned int ver); 00042 00043 friend class WriteNeXusFile; 00047 template <class Write> 00048 void NXwrite(Write &W) const ; 00049 00050 friend class ReadNeXusFile; 00054 template <class Read> 00055 void NXread(Read &R) ; 00056 00057 protected: 00058 00059 public: 00060 UInt4Container(); 00061 UInt4Container( HeaderBase *Header ); 00062 //UInt4Container( HeaderBase Header ); 00063 00064 UInt4Container( const UInt4Container &ob ); 00065 UInt4Container operator=( const UInt4Container &ob ); 00066 00067 ~UInt4Container(); 00068 00069 UInt4 PutTableSize(){ return v.size(); } 00070 UInt4 PutSize(){ return PutTableSize(); } 00071 00072 UInt4 PutTableSizeDouble(){ return vd.size(); } 00073 UInt4 PutSizeDouble(){ return PutTableSizeDouble(); } 00074 00075 UInt4 PutSize( UInt4 IndexNumber ){ return v[IndexNumber] -> size(); } 00076 UInt4 PutSize( string Key ){ return Put(Key) . size(); } 00077 00078 UInt4 PutSizeDouble( UInt4 IndexNumber ){ return vd[IndexNumber] -> size(); } 00079 UInt4 PutSizeDouble( string Key ){ return PutDouble(Key) . size(); } 00080 00081 UInt4 PutIndexNumber( string Key ); 00082 UInt4 PutIndexNumberDouble( string Key ); 00083 00084 string PutName( UInt4 IndexNumber ){ return s[IndexNumber]; } 00085 string PutNameDouble( UInt4 IndexNumber ){ return sd[IndexNumber]; } 00086 00087 HeaderBase PutHeader(); 00088 HeaderBase *PutHeaderPointer(){ return header; } 00089 void InputHeader( HeaderBase Header ); 00090 00092 void Reverse(void) { 00093 std::cout << "UInt4Container::Reverse() not implemented yet" << std::endl; 00094 } 00095 00096 void DumpKey(); 00097 void Dump(); 00098 void DumpValue(); 00099 void DumpFromVectorContainer(); 00100 void DumpFromVectorContainer( UInt4 size ); 00101 void Dump( UInt4 size ); 00102 void DumpValue( UInt4 size ); 00103 00104 void Add( string Key, vector< UInt4 > value ); 00105 void Add( string Key, PyObject *value ); 00106 void Add( string Key, UInt4 *&Array, UInt4 ArraySize ); 00107 00108 void AddDouble( string Key, vector< Double > value ); 00109 void AddDouble( string Key, PyObject *value ); 00110 void AddDouble( string Key, Double *&Array, UInt4 ArraySize ); 00111 00112 vector<UInt4> Put( UInt4 IndexNumber ); 00113 vector<Double> PutDouble( UInt4 IndexNumber ); 00114 vector<UInt4> Put( string Key ); 00115 vector<Double> PutDouble( string Key ); 00116 UInt4 Put( string Key, UInt4 Index ); 00117 Double PutDouble( string Key, UInt4 Index ); 00118 00119 PyObject *PutList( string Key ); 00120 PyObject *PutListDouble( string Key ); 00121 UInt4 CheckKey( string Key ); 00122 UInt4 CheckKeyDouble( string Key ); 00123 00124 // These methods will be utilized for making NeXus file. 00125 string PutMergedKey(); 00126 string PutMergedKeyDouble(); 00127 vector<UInt4> PutSizeVector(); 00128 vector<UInt4> PutSizeVectorDouble(); 00129 vector<UInt4> PutMergedDataVector(); 00130 vector<Double> PutMergedDataVectorDouble(); 00131 00132 // A data container will be built with the arguments of this method, 00133 // and this method will be called from "ReadNeXusFile" and "WriteNeXusFile". 00134 void MakeContainer( string MergedKey, 00135 vector<UInt4> SizeVector, 00136 vector<UInt4> MergedDataVector, 00137 HeaderBase h ); 00143 void MakeContainer( string MergedKey, 00144 vector<UInt4> SizeVector, 00145 vector<UInt4> MergedDataVector, 00146 string MergedKeyDouble, 00147 vector<UInt4> SizeVectorDouble, 00148 vector<Double> MergedDataVectorDouble, 00149 HeaderBase h ); 00152 vector<UInt4>* operator[]( string Key ); 00156 vector<UInt4>* operator[]( UInt4 index ); 00160 vector<UInt4>* operator()( string Key ); 00164 vector<UInt4>* operator()( UInt4 index ); 00169 ElementContainer ConvertIntoElementContainer(); 00175 00176 UInt4Container &operator+=(const UInt4Container &r) { 00177 std::cout << "operator += for UInt4Container was not implemented" << std::endl; 00178 return *this; 00179 } 00181 UInt4Container &operator-=(const UInt4Container &r) { 00182 std::cout << "operator -= for UInt4Container was not implemented" << std::endl; 00183 return *this; 00184 } 00186 UInt4Container &operator*=(const UInt4Container &r) { 00187 std::cout << "operator *= for UInt4Container was not implemented" << std::endl; 00188 return *this; 00189 } 00191 UInt4Container &operator/=(const UInt4Container &r) { 00192 std::cout << "operator /= for UInt4Container was not implemented" << std::endl; 00193 return *this; 00194 } 00195 00197 UInt4Container operator+(UInt4Container &r) { 00198 std::cout << "operator + for UInt4Container was not implemented" << std::endl; 00199 return *this; 00200 } 00202 UInt4Container operator-(UInt4Container &r) { 00203 std::cout << "operator - for UInt4Container was not implemented" << std::endl; 00204 return *this; 00205 } 00207 UInt4Container operator*(UInt4Container &r) { 00208 std::cout << "operator * for UInt4Container was not implemented" << std::endl; 00209 return *this; 00210 } 00212 UInt4Container operator/(UInt4Container &r) { 00213 std::cout << "operator / for UInt4Container was not implemented" << std::endl; 00214 return *this; 00215 } 00216 }; 00217 00219 template <class Archive> 00220 void UInt4Container:: 00221 serialize(Archive &ar, const unsigned int ver) { 00222 ar & boost::serialization::make_nvp("UInt4Keys", s); 00223 ar & boost::serialization::make_nvp("UInt4Values", v); 00224 00225 ar & boost::serialization::make_nvp("DoubleKeys", sd); 00226 ar & boost::serialization::make_nvp("DoubleValues", vd); 00227 00228 ar & boost::serialization::make_nvp("Header", *header); 00229 } 00230 00232 template <class Write> 00233 void UInt4Container:: 00234 NXwrite(Write &W) const { 00235 W.WriteData("UInt4Keys", s); 00236 W.WriteData("UInt4Values", v); 00237 00238 W.WriteData("DoubleKeys", sd); 00239 W.WriteData("DoubleValues", vd); 00240 00241 if (!header->Empty()) 00242 W.WriteData("Header", *header); 00243 } 00244 00246 template <class Read> 00247 void UInt4Container:: 00248 NXread(Read &R) { 00249 R.ReadData("UInt4Keys", s); 00250 R.ReadData("UInt4Values", v); 00251 00252 R.ReadData("DoubleKeys", sd); 00253 R.ReadData("DoubleValues", vd); 00254 00255 NXname _name, _class; 00256 int _id, _status; 00257 while ((_status=R.GetNextEntry2(_name, _class, &_id))==1) { 00258 // std::cerr << "NEXTENTRY: " << _name << "," << _class << ", " 00259 // << _id << "," << _status << std::endl; 00260 if (strcmp(_name, "Header")==0) 00261 R.ReadData("Header", *header); 00262 } 00263 } 00264 #endif 00265