ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RooStringVar.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooStringVar.cxx
19 \class RooStringVar
20 \ingroup Roofitcore
21 
22 RooStringVar implements a string values RooAbsArg
23 **/
24 
25 #include "RooFit.h"
26 #include "Riostream.h"
27 
28 #include <math.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include "TObjString.h"
33 #include "TTree.h"
34 #include "RooStringVar.h"
35 #include "RooStreamParser.h"
36 #include "RooMsgService.h"
37 
38 
39 
40 using namespace std;
41 
43 
44 
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Constructor with initial value and internal buffer size
49 
50 RooStringVar::RooStringVar(const char *name, const char *title, const char* value, Int_t size) :
51  RooAbsString(name, title, size)
52 {
53  if(!isValidString(value)) {
54  coutW(InputArguments) << "RooStringVar::RooStringVar(" << GetName()
55  << "): initial contents too long and ignored" << endl ;
56  } else {
57  strlcpy(_value,value,_len) ;
58  }
59 
60  setValueDirty() ;
61  setShapeDirty() ;
62 }
63 
64 
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Copy constructor
68 
69 RooStringVar::RooStringVar(const RooStringVar& other, const char* name) :
70  RooAbsString(other, name)
71 {
72 }
73 
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Destructor
78 
80 {
81 }
82 
83 
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 
87 RooStringVar::operator TString()
88 {
89  // Cast operator to TString
90  return TString(_value) ;
91 }
92 
93 
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Set value to given TString
97 
98 void RooStringVar::setVal(const char* value)
99 {
100  if (!isValidString(value)) {
101  coutW(InputArguments) << "RooStringVar::setVal(" << GetName() << "): new string too long and ignored" << endl ;
102  } else {
103  if (value) {
104  strlcpy(_value,value,_len) ;
105  } else {
106  _value[0] = 0 ;
107  }
108  }
109 }
110 
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Set value to given TString
115 
116 RooAbsArg& RooStringVar::operator=(const char* newValue)
117 {
118  if (!isValidString(newValue)) {
119  coutW(InputArguments) << "RooStringVar::operator=(" << GetName() << "): new string too long and ignored" << endl ;
120  } else {
121  if (newValue) {
122  strlcpy(_value,newValue,_len) ;
123  } else {
124  _value[0] = 0 ;
125  }
126  }
127 
128  return *this ;
129 }
130 
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Read object contents from given stream
135 
137 {
138  TString token,errorPrefix("RooStringVar::readFromStream(") ;
139  errorPrefix.Append(GetName()) ;
140  errorPrefix.Append(")") ;
141  RooStreamParser parser(is,errorPrefix) ;
142 
143  TString newValue ;
144  Bool_t ret(kFALSE) ;
145 
146  if (compact) {
147  parser.readString(newValue,kTRUE) ;
148  } else {
149  newValue = parser.readLine() ;
150  }
151 
152  if (!isValidString(newValue)) {
153  if (verbose)
154  coutW(InputArguments) << "RooStringVar::readFromStream(" << GetName()
155  << "): new string too long and ignored" << endl ;
156  } else {
157  strlcpy(_value,newValue,_len) ;
158  }
159 
160  return ret ;
161 }
162 
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Write object contents to given stream
166 
167 void RooStringVar::writeToStream(ostream& os, Bool_t /*compact*/) const
168 {
169  os << getVal() ;
170 }
171 
172 
virtual Bool_t isValidString(const char *, Bool_t printError=kFALSE) const
Check if given string value is valid.
virtual void setVal(const char *newVal)
Set value to given TString.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
#define coutW(a)
Definition: RooMsgService.h:34
TString & Append(const char *cs)
Definition: TString.h:492
ClassImp(RooStringVar) RooStringVar
Constructor with initial value and internal buffer size.
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual RooAbsArg & operator=(const char *newValue)
Set value to given TString.
char * _value
Definition: RooAbsString.h:68
bool verbose
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
Bool_t readString(TString &value, Bool_t zapOnError=kFALSE)
Read a string token.
virtual ~RooStringVar()
Destructor.
virtual const char * getVal() const
Return value of object. Calculated if dirty, otherwise cached value is returned.
Definition: RooStringVar.h:35
#define name(a, b)
Definition: linkTestLib0.cpp:5
RooAbsString is the common abstract base class for objects that represent a string value...
Definition: RooAbsString.h:25
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
RooStringVar implements a string values RooAbsArg.
Definition: RooStringVar.h:24
float value
Definition: math.cpp:443
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.