Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TStringLong.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 15/11/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TStringLong
13 ATTENTION: this class is obsolete. It's functionality has been taken
14 over by TString.
15 
16 The long string class (unlimited number of chars in I/O).
17 
18 This class redefines only the I/O member functions of TString.
19 It uses 4 bytes to store the string length (1 byte only for TString).
20 */
21 
22 #include "TStringLong.h"
23 #include "TBuffer.h"
24 #include "Bytes.h"
25 
26 // Remove to avoid deprecation warnings during root build
27 //ClassImp(TStringLong);
28 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 ///constructor
32 
33 TStringLong::TStringLong() : TString()
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 ///constructor
39 
40 TStringLong::TStringLong(Ssiz_t ic) : TString(ic)
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 ///copy constructor
46 
47 TStringLong::TStringLong(const TString& s) : TString(s)
48 {
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 ///copy constructor
53 
54 TStringLong::TStringLong(const char* cs) : TString(cs)
55 {
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 ///constructor from a char*
60 
61 TStringLong::TStringLong(const char* cs, Ssiz_t n) : TString(cs,n)
62 {
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 ///constructor from a char
67 
68 TStringLong::TStringLong(char c) : TString(c)
69 {
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 ///constructor from a char
74 
75 TStringLong::TStringLong(char c, Ssiz_t n) : TString(c,n)
76 {
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 ///constructor from a substring
81 
82 TStringLong::TStringLong(const TSubString& substr) : TString(substr)
83 {
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 ///destructor
88 
89 TStringLong::~TStringLong()
90 {
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Fill buffer.
95 
96 void TStringLong::FillBuffer(char *&buffer) const
97 {
98  Int_t nchars = Length();
99  tobuf(buffer, nchars);
100  const char *data = GetPointer();
101  for (Int_t i = 0; i < nchars; i++) buffer[i] = data[i];
102  buffer += nchars;
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Read this string from the buffer.
107 
108 void TStringLong::ReadBuffer(char *&buffer)
109 {
110  UnLink();
111  Zero();
112 
113  Int_t nchars;
114  frombuf(buffer, &nchars);
115 
116  char *data = Init(nchars, nchars);
117 
118  for (Int_t i = 0; i < nchars; i++) frombuf(buffer, &data[i]);
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Return the sizeof the string.
123 
124 Int_t TStringLong::Sizeof() const
125 {
126  return Length()+sizeof(Int_t);
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Stream a long (>255 characters) string object.
131 
132 void TStringLong::Streamer(TBuffer &b)
133 {
134  Int_t nwh;
135  if (b.IsReading()) {
136  b >> nwh;
137  Clobber(nwh);
138  char *data = GetPointer();
139  data[nwh] = 0;
140  SetSize(nwh);
141  for (int i = 0; i < nwh; i++) b >> data[i];
142  } else {
143  nwh = Length();
144  b << nwh;
145  const char *data = GetPointer();
146  for (int i = 0; i < nwh; i++) b << data[i];
147  }
148 }