TDbiRegistryItemXxx.cxx

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////
00002 //
00003 // $Id: TDbiRegistryItemXxx.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $
00004 //
00005 // TDbiRegistryItemXxx
00006 //
00007 // Package: TDbiRegistry
00008 //
00009 // see header file for comments.
00010 //
00011 // Contact: bv@bnl.gov
00012 //
00013 // Created on: Wed Oct 25 17:16:38 2000
00014 //
00015 ////////////////////////////////////////////////////////////////////////
00016 
00017 
00018 #include <TBuffer.h>
00019 #include <TObject.h>
00020 
00021 #include "TDbiRegistryItem.hxx"
00022 #include "TDbiRegistryItemXxx.hxx"
00023 
00024 #include <UtilStream.hxx>
00025 
00026 #include <string>
00027 // Only for GCC 3.3 and above.  See bug 3797
00028 
00029 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3797
00030 #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ >=4 )
00031 template<> const char* TDbiRegistryItemXxx<char>::GetTypeAsString(void) const
00032 { return "char"; }
00033 
00034 template<> const char* TDbiRegistryItemXxx<int>::GetTypeAsString(void) const
00035 { return "int"; }
00036 
00037 template<> const char* TDbiRegistryItemXxx<double>::GetTypeAsString(void) const
00038 { return "double"; }
00039 
00040 template<> const char* TDbiRegistryItemXxx<const char*>::GetTypeAsString(void) const
00041 { return "string"; }
00042 
00043 template<> const char* TDbiRegistryItemXxx<TDbiRegistry>::GetTypeAsString(void) const
00044 { return "TDbiRegistry"; }
00045 
00046 template<> std::ostream& TDbiRegistryItemXxx<TDbiRegistry>::PrintStream(std::ostream& os) const
00047 { return fData->PrintStream(os); }
00048 
00049 template<> std::istream& TDbiRegistryItemXxx<TDbiRegistry>::ReadStream(std::istream& is)
00050 { if (!fData) fData = new TDbiRegistry(); return fData->ReadStream(is); }
00051 #endif
00052 
00053 
00054 TBuffer& operator>>(TBuffer &buf, int*& xptr)
00055 {
00056     int x;
00057     buf >> x;
00058     xptr = new int(x);
00059     return buf;
00060 }
00061 TBuffer& operator>>(TBuffer &buf, double*& xptr)
00062 {
00063     double x;
00064     buf >> x;
00065     xptr = new double(x);
00066     return buf;
00067 }
00068 TBuffer& operator>>(TBuffer &buf, float*& xptr)
00069 {
00070     float x;
00071     buf >> x;
00072     xptr = new float(x);
00073     return buf;
00074 }
00075 
00076 #if 0
00077 TBuffer& operator>>(TBuffer &buf, bool*& xptr)
00078 {
00079     int i;
00080     buf >> i;
00081     if (i) xptr = new bool(true);
00082     else   xptr = new bool(false);
00083     return buf;
00084 }
00085 #endif
00086 
00087 //......................................
00088 
00089 TBuffer& operator<<(TBuffer &buf, int*& xptr)
00090 {
00091     buf << *xptr;
00092     return buf;
00093 }
00094 TBuffer& operator<<(TBuffer &buf, double*& xptr)
00095 {
00096     buf << *xptr;
00097     return buf;
00098 }
00099 TBuffer& operator<<(TBuffer &buf, float*& xptr)
00100 {
00101     buf << *xptr;
00102     return buf;
00103 }
00104 #if 0
00105 TBuffer& operator<<(TBuffer &buf, bool*& xptr)
00106 {
00107     buf << (*xptr ? 1 : 0);
00108     return buf;
00109 }
00110 #endif
00111 
00112 #if 0
00113 TBuffer& operator<<(TBuffer &buf, const char*& xptr)
00114 {
00115     const char *x = xptr;
00116     --x;
00117     do {
00118         ++x;
00119         buf  << *x;
00120     } while (*x);
00121     return buf;
00122 }
00123 #endif
00124 #include <string>
00125 
00126 template<>
00127 void TDbiRegistryItemXxx<const char*>::Streamer(TBuffer &buf)
00128 {
00129     if (buf.IsReading()) {
00130         Version_t v = buf.ReadVersion();
00131         if (v) { }
00132         TDbiRegistryItem::Streamer(buf);
00133 
00134         std::string str = "";
00135         char x[2];
00136         x[1] = '\0';
00137 
00138         do {                    // read out string one byte at a time
00139             buf >> x[0];
00140             str += x;
00141         } while (x[0]);
00142 
00143         char** ppchar = new char*;
00144         *ppchar = new char[str.length() + 1];
00145         strcpy(*ppchar,str.c_str());
00146         (*ppchar)[str.length()] = '\0'; // paranoia
00147         fData = const_cast<const char**>(ppchar);
00148     }
00149     else {
00150         buf.WriteVersion(IsA());
00151         TDbiRegistryItem::Streamer(buf);
00152         buf << (*fData);
00153     }
00154 
00155 
00156 }
00157 
00158 // Must do this special because ROOT treats char and char* asymmetric
00159 template<>
00160 void TDbiRegistryItemXxx<char>::Streamer(TBuffer &buf)
00161 {
00162     if (buf.IsReading()) {
00163         Version_t v = buf.ReadVersion();
00164         if (v) { }
00165         TDbiRegistryItem::Streamer(buf);
00166 
00167         char c;
00168         buf >> c;
00169         fData = new char(c);
00170     }
00171     else {
00172         buf.WriteVersion(IsA());
00173         TDbiRegistryItem::Streamer(buf);
00174         buf << *fData;
00175     }
00176 }
00177 
00178 template<>
00179 std::ostream& TDbiRegistryItemXxx<const char*>::PrintStream(std::ostream& os) const
00180 {
00181     os << "'" << *fData << "'";
00182     return os;
00183 }
00184 
00185 #include<string>
00186 template<>
00187 std::istream& TDbiRegistryItemXxx<const char*>::ReadStream(std::istream& is)
00188 {
00189   std::string stot = Util::read_quoted_string(is);
00190 
00191     if (!fData) {
00192         char** ppchar = new char*;
00193         *ppchar = 0;
00194         fData = const_cast<const char**>(ppchar);
00195     }
00196     if (*fData) delete [] *fData;
00197 
00198     char* pchar = new char[stot.length() + 1];
00199     strcpy(pchar,stot.c_str());
00200     *fData = const_cast<const char*>(pchar);
00201     return is;
00202 }
00203 
00204 
00205 template<>
00206 TDbiRegistryItemXxx<const char*>::~TDbiRegistryItemXxx()
00207 {
00208     if (fData) {
00209         if (*fData) {
00210             delete [] *fData;
00211             *fData = 0;
00212         }
00213         delete fData;
00214         fData = 0;
00215     }
00216 }
00217 
00218 template<>
00219 TDbiRegistryItem* TDbiRegistryItemXxx<const char*>::Dup(void) const
00220 {
00221     char** ppc = new char*;
00222     (*ppc) = new char [strlen(*fData)+1];
00223     strcpy(*ppc,*fData);
00224     const char** ppcc = const_cast<const char**>(ppc);
00225     return new TDbiRegistryItemXxx< const char* >(ppcc);
00226 }
00227 
00228 
00229 

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1