メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

Ttypes.h

解説を見る。
00001 // =====================================================================
00023 // =====================================================================
00024 #ifndef CLDAQ_IODLL__TTYPES_H
00025 #define CLDAQ_IODLL__TTYPES_H
00026 
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <fstream>
00030 #include <string>
00031 #include <list>
00032 #include <vector>
00033 #include <map>
00034 #if (__GNUC__==3) && (__GNUC_MINOR__>0)
00035 #undef __DEPRECATED
00036 #endif
00037 #include <strstream>
00038 #include <stdio.h>
00039 #include <unistd.h>
00040 
00041 #define Tfalse 0
00042 #define Ttrue 1
00043 #define Tios std::ios
00044 #define Tlist std::list
00045 #define Tvector std::vector
00046 #define Tmap std::map
00047 #define Tmultimap std::multimap
00048 #define Tpair std::pair
00049 #define Tcin std::cin
00050 #define Tendl std::endl
00051 #define Tends std::ends
00052 #define Tdec std::dec
00053 #define Thex std::hex
00054 #define Toct std::oct
00055 #define Tflush std::flush
00056 #define Tsizeof(_type_) sizeof(_type_)
00057 
00058 #define Tcout std::cout
00059 #define Tcerr std::cerr
00060 #define Tclog std::clog
00061 
00062 typedef double Tdouble;
00063 typedef int Tint;
00064 typedef float Tfloat;
00065 typedef char Tchar;
00066 typedef long Tlong;
00067 typedef unsigned char TUchar;
00068 typedef unsigned int TUint;
00069 typedef unsigned long TUlong;
00070 typedef short Tshort;
00071 typedef unsigned short TUshort;
00072 typedef bool Tbool;
00073 typedef Tbool Tbit;
00074 typedef FILE TFileStream;
00075 typedef size_t Tsize_t;
00076 typedef void Tvoid;
00077 
00078 
00079 typedef std::string Tstring;
00080 typedef std::ofstream Tofstream;
00081 typedef std::ifstream Tifstream;
00082 typedef std::ostream Tostream;
00083 typedef std::ostrstream Tostrstream;
00084 typedef std::istream Tistream;
00085 
00086 
00087 typedef Tvector<Tint> TintList;
00088 typedef Tvector<TUint> TUintList;
00089 typedef Tvector<TUshort> TUshortList;
00090 typedef Tvector<Tdouble> TdoubleList;
00091 typedef Tvector<Tfloat> TfloatList;
00092 typedef Tvector<Tstring> TstringList;
00093 
00094 
00095 
00096 const Tstring Tslash = "/";
00097 const Tstring Ttab = "\t";
00098 const Tstring Thour = "h";
00099 const Tstring Tmin = "m";
00100 const Tstring Tsec = "s";
00101 const Tstring Tmsec = "ms";
00102 const Tstring Tusec = "us";
00103 const Tstring Tnsec = "ns";
00104 const Tchar Tkey = '\x01';
00105 
00106 enum Tobject_t { 
00107   tObjectDataRecord,
00108   tObjectDataSection,
00109   tObjectDataSegment,
00110   tObjectDataElement,
00111   tObject1DHistogram,
00112   tObject2DHistogram,
00113   tObjectAppendGraph,
00114   tObjectSubstituteGraph,
00115   tObjectNtuple,
00116   tNumberOfObjectTypes,
00117   tObjectUnknown = -1
00118 };
00119 
00120 enum Telement_t {
00121   tTypeInt,
00122   tTypeString,
00123   tTypeDouble,
00124   tTypeObject,
00125   tTypeFloat,
00126   tTypeUnsignedShort,
00127   tTypeShort,
00128   tTypeWord,
00129   tTypeLong,
00130   tTypeUnsignedLong,
00131   tTypeUnsignedInt,
00132   tNumberOfElementTypes,
00133   tTypeUnknown = -1
00134 };
00135 
00136 enum Tstream_t { 
00137   tFileStream,
00138   tSocketStream,
00139   tSharedMemoryStream,
00140   tNumberOfStreamTypes,
00141   tUnknownStream = -1
00142 };
00143 
00144 enum Trandom_t {
00145   tRandomExponential,
00146   tRandomGaussian,
00147   tRandomChiSquare,
00148   tRandomLandau,
00149   tRandomGamma,
00150   tRandomPoisson,
00151   tNumberOfRandomTypes,
00152   tRandomUnknown = -1
00153 };
00154 
00155 enum Tstatus_t {
00156   tStatusStandby,
00157   tStatusReady,
00158   tStatusBusy,
00159   tStatusIdle,
00160   tStatusWaitingReady,
00161   tStatusJustTakingEvent,
00162   tStatusJustRecordingEvent,
00163   tStatusSleep,
00164   tStatusDead,
00165   tNumberOfStatusTypes,
00166   tStatusUnknown = -1
00167 };
00168 
00169 enum TvmeTransfer_t {
00170   tA16D16,
00171   tA16D32,
00172   tA24D16,
00173   tA24D32,
00174   tA32D16,
00175   tA32D32,
00176   tA24D16dma,
00177   tA32D16dma,
00178   tA24D32dma,
00179   tA32D32dma, 
00180   tNumberOfVmeTransferModes,
00181   tTransferModeUnknown = -1
00182 };
00183 
00184 enum { 
00185   tIDunknown = -1
00186 };
00187 
00188 const Tstring TunknownID = "unkown ID";
00189 
00190 
00191 inline static Tstring itostr( Tint i, Tint digits = 6 )
00192 {
00193   static const Tsize_t _buflen = 0x100;
00194   static Tchar buf[ _buflen + 1 ];
00195   Tostrstream os( buf, _buflen );
00196 
00197   if ( i >= 0 ) {
00198     os << std::setfill( '0' ) << std::setiosflags( Tios::right ) << std::setw( digits );
00199     os << i << Tends;
00200     Tstring s = os.str();
00201     return s;
00202   } else {
00203     os << i << Tends;
00204     Tstring s = os.str();
00205     Tint nzero = digits - s.size();
00206     if ( nzero > 0 ) {
00207       s.insert( 1, nzero, '0' );
00208     }
00209     return s;
00210   }
00211 }
00212 
00213 inline static Tstring ltostr( Tlong l, Tint digits = 6 )
00214 {
00215   static const Tsize_t _buflen = 0x100;
00216   static Tchar buf[ _buflen + 1 ];
00217   Tostrstream os( buf, _buflen );
00218 
00219   if ( l >= 0 ) {
00220     os << std::setfill( '0' ) << std::setiosflags( Tios::right ) << std::setw( digits );
00221     os << l << Tends;
00222     Tstring s = os.str();
00223     return s;
00224   } else {
00225     os << l << Tends;
00226     Tstring s = os.str();
00227     Tint nzero = digits - s.size();
00228     if ( nzero > 0 ) {
00229       s.insert( 1, nzero, '0' );
00230     }
00231     return s;
00232   }
00233 }
00234 
00235 inline static Tstring ultostr( TUlong ul, Tint digits = 6 )
00236 {
00237   static const Tsize_t _buflen = 0x100;
00238   static Tchar buf[ _buflen + 1 ];
00239   Tostrstream os( buf, _buflen );
00240 
00241   if ( ul >= 0 ) {
00242     os << std::setfill( '0' ) << std::setiosflags( Tios::right ) << std::setw( digits );
00243     os << ul << Tends;
00244     Tstring s = os.str();
00245     return s;
00246   } else {
00247     os << ul << Tends;
00248     Tstring s = os.str();
00249     Tint nzero = digits - s.size();
00250     if ( nzero > 0 ) {
00251       s.insert( 1, nzero, '0' );
00252     }
00253     return s;
00254   }
00255 }
00256 
00257 inline static Tstring dtostr( Tdouble d, Tint precision = 6 )
00258 {
00259   static const Tsize_t _buflen = 0x100;
00260   static Tchar buf[ _buflen + 1 ];
00261   Tostrstream os( buf, _buflen );
00262 
00263   os << std::setprecision( precision ) << d << Tends;
00264   Tstring s = os.str();
00265   return s;
00266 }
00267 
00268 inline static Tstring ftostr( Tfloat f, Tint precision = 6 )
00269 {
00270   return dtostr( (Tdouble)f, precision );
00271 }
00272 
00273 #include <unistd.h>
00274 
00275 inline static Tbool isexist( const Tstring& filename, Tint mode = R_OK|F_OK )
00276 {
00277   if ( access( filename.c_str(), mode ) == 0 ) {
00278     return Ttrue;
00279   } else {
00280     return Tfalse;
00281   }
00282 }
00283 
00284 #include <stdlib.h>
00285 inline static Tint strtoi( const Tstring& nptr, Tchar** endptr = 0, Tint base = 0 )
00286 {
00287   return (Tint)strtol( nptr.c_str(), endptr, base );
00288 }
00289 
00290 inline static Tdouble strtod( const Tstring& nptr, Tchar** endptr )
00291 {
00292   return strtod( nptr.c_str(), endptr );
00293 }
00294 
00295 #include <libgen.h>
00296 inline static Tstring basename( const Tstring& path )
00297 {
00298   const Tsize_t len = path.size() + 1;
00299   Tchar* copy = new Tchar[ len ];
00300   //path.copy( copy, path.size() ); // std::string::copy has bugs.
00301   strncpy( copy, path.c_str(), len );
00302   Tchar* b = basename( copy );
00303   Tstring base( b );
00304   delete [] copy;
00305   return base;
00306 }
00307 
00308 inline static Tstring dirname( const Tstring& path )
00309 {
00310   const Tsize_t len = path.size() + 1;
00311   Tchar* copy = new Tchar[ len ];
00312   //path.copy( copy, path.size() ); // std::string::copy has bugs.
00313   strncpy( copy, path.c_str(), len );
00314   Tchar* d = dirname( copy );
00315   Tstring dir( d );
00316   delete [] copy;
00317   return dir;
00318 }
00319 
00320 
00321 #define CLDAQ_DEBUG(m) \
00322 if ( strlen(m) ) {\
00323   Tcout << "[CLDAQ:DEBUG]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00324 } else {\
00325   Tcout << "[CLDAQ:DEBUG]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00326 }
00327 #define CLDAQ_WARN(m) \
00328 if ( strlen(m) ) {\
00329   Tcerr << "[CLDAQ:WARNIG]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00330 } else {\
00331   Tcerr << "[CLDAQ:WARNIG]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00332 }\
00333 perror( "[CLDAQ:WARNING]" );
00334 #define CLDAQ_EMERG(m) \
00335 if ( strlen(m) ) {\
00336   Tcerr << "[CLDAQ:EMERG]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00337 } else {\
00338   Tcerr << "[CLDAQ:EMERG]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00339 }\
00340 perror( "[CLDAQ:EMERG]" );\
00341 abort();
00342 #define CLDAQ_ABORT(m) CLDAQ_EMERG(m)
00343 #define CLDAQ_EXIT(m) \
00344 if ( strlen(m) ) {\
00345   Tcerr << "[CLDAQ:EXIT]: " << m << " in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00346 } else {\
00347   Tcerr << "[CLDAQ:EXIT]: in \"" << __PRETTY_FUNCTION__ << "\" at " << __FILE__ << " line " << __LINE__ << "." << Tendl;\
00348 }\
00349 perror( "[CLDAQ:EXIT]" );\
00350 exit(EXIT_SUCCESS);
00351 
00352 
00353 using namespace std;
00354 
00355 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp