GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DotConf.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef ADF_DotConf
24 #define ADF_DotConf
25 
26 #ifndef _ADFConfig
27 #include "ADFConfig.h"
28 #endif
29 #include "ADFLogMessage.h"
30 
31 #include <list>
32 
33 namespace ADF
34 {
35 
36 class ConfigurationFrame;
37 
39 
80 
82 
96 class DotConf
97 {
98 protected:
101 
102 private:
104  struct HeaderDef {
105  HeaderDef(Char_t skip = '#', Bool_t is_record = false, std::string rid = "", std::string srid = "", Short_t version = -1) : fSkipLine(skip), fWithRecord(is_record), fRID(rid), fSRID(srid), fVersion(version)
106  {;}
108  Char_t fSkipLine;
110  Bool_t fWithRecord;
112  std::string fRID;
114  std::string fSRID;
116  Short_t fVersion;
117  };
118  HeaderDef fHeaderDef;
119 
120 private:
122  struct Header {
123  Header(Short_t version, Short_t pversion, std::string streamopt = "Init") : fVersion(version), fPreviousVersion(pversion), fStreamOption(streamopt)
124  {;}
126  Short_t fVersion;
128  Short_t fPreviousVersion;
130  std::string fStreamOption;
131  };
132  Header fHeader;
133 
134 private:
136  std::list< DotConf * > fListOfDotConf;
137 
138 private:
141  std::string fLastModif;
143  std::string fComment;
144 
145 protected:
147  std::string BeginOfRecord();
149  std::string EndOfRecord();
151 
163  Bool_t IsBeginOfRecord(const std::string &, Bool_t allow_init);
165  Bool_t IsEndOfRecord(const std::string &);
167  Bool_t AddRecord(std::ostream &, char t = 'b');
168 
169 protected:
171  void SetLastModif();
173  void SetVersion(Short_t v)
174  { fHeader.fVersion = v; }
176  void SetMaxVersion(Short_t v)
177  { fHeaderDef.fVersion = v; }
178 
179 public:
181 
184  /*
185  template <class Data_t> Data_t *DoClone(Data_t *newobj)
186  {
187  newobj = new Data_t ();
188  if ( newobj == 0x0 )
189  return 0x0;
190 
191  // use DotConf facilities to clone
192  Bool_t ok = true;
193  //
194  std::ostringstream o;
195  ok = ok &&
196  this->DoConfigure(o);
197  //
198  // std::string tmp;
199  // tmp = o.str();
200  std::istringstream i(o.str());
201  ok = ok &&
202  newobj->DoConfigure(i,true); //
203 
204  if ( !ok )
205  { delete newobj; newobj = 0x0; }
206 
207  return newobj;
208  }
209  */
210 
211 protected:
213 
216  virtual Bool_t ProcessLine(const std::string &)
217  { return true; }
218 
219 public:
220  DotConf();
221  DotConf(const Char_t *rid, const Char_t *srid = "", Bool_t is_record = true);
222  virtual ~DotConf();
223 
224 // Get/Set method
225 public:
227  Bool_t IsWithRecord() const
228  { return fHeaderDef.fWithRecord; }
230  void SetWithRecord(Bool_t is_record = true)
231  { fHeaderDef.fWithRecord = is_record; }
232 
233  void SetComment(const Char_t *comment)
234  { fComment = comment ; }
235  const Char_t *GetComment() const
236  { return fComment.data(); }
237 
238  const Char_t *GetLastModif() const
239  { return fLastModif.data(); }
240 
242  Short_t GetMaxVersion() const
243  {return fHeaderDef.fVersion;}
244 
246  virtual void Reset(const Char_t *opt = "");
247 
249  virtual void SetRID(const Char_t *rid, const Char_t *srid ="")
250  { fHeaderDef.fRID = rid; fHeaderDef.fSRID = srid; }
252  virtual const Char_t *GetRID() const
253  { return fHeaderDef.fRID.data(); }
255  virtual const Char_t *GetSRID() const
256  { return fHeaderDef.fSRID.data(); }
258  virtual Short_t GetVersion() const
259  { return fHeader.fVersion; }
260 
262  virtual const Char_t *GetStreamOption() const
263  { return fHeader.fStreamOption.data(); }
264  virtual void SetStreamOption(const Char_t *opt)
265  { fHeader.fStreamOption = opt; }
266 
268 
271  virtual void AddConf ( DotConf * );
272  // clear conf list
273  virtual void RemoveConf ( DotConf *aconf = 0x0 )
274  {
275  if ( aconf == 0x0 )
276  fListOfDotConf.clear();
277  else
278  fListOfDotConf.remove(aconf);
279  }
280 
281 // Interface for any DotConf object
282 public:
284 
291  virtual Bool_t DoConfigure(std::istream &, Bool_t allow_init);
293 
297  virtual Bool_t DoConfigure(std::ostream &);
298 
300 
305  virtual Bool_t Configure(ConfigurationFrame *, const char *option = "in", Bool_t allow_init = false);
307  virtual Bool_t Configure(const char *name, const char *option = "in", Bool_t allow_init = true);
308 };
309 
310 } // namespace ADF
311 
312 #endif
313 
314 
315 
316 
317 
318 
319 
320 
void SetVersion(Short_t v)
Definition: DotConf.h:173
DotConf : Utility for class configuration from ascii file or Configuration frames.
Definition: DotConf.h:96
const Char_t * GetComment() const
Definition: DotConf.h:235
std::string BeginOfRecord()
string that gives a start of record for this object
Definition: DotConf.cpp:93
virtual Short_t GetVersion() const
to get the curent version of this object
Definition: DotConf.h:258
virtual const Char_t * GetSRID() const
to get the record id
Definition: DotConf.h:255
void SetLastModif()
set in last modif string the current date.
Definition: DotConf.cpp:105
Short_t GetMaxVersion() const
this class could managed moddification of the versionned part up to MaxVersion : should be set in the...
Definition: DotConf.h:242
A configuration frame is just an encapsulation of a string.
virtual const Char_t * GetRID() const
to get the record id
Definition: DotConf.h:252
void SetComment(const Char_t *comment)
Definition: DotConf.h:233
Bool_t IsEndOfRecord(const std::string &)
Return true if this string is an end of record.
Definition: DotConf.cpp:187
virtual void Reset(const Char_t *opt="")
Reset : all values are set to default.
Definition: DotConf.cpp:115
std::string EndOfRecord()
string that gives an end of record for this object
Definition: DotConf.cpp:99
virtual void SetRID(const Char_t *rid, const Char_t *srid="")
to set the record id
Definition: DotConf.h:249
virtual void RemoveConf(DotConf *aconf=0x0)
Definition: DotConf.h:273
virtual ~DotConf()
Definition: DotConf.cpp:69
virtual Bool_t Configure(ConfigurationFrame *, const char *option="in", Bool_t allow_init=false)
configuration from/to a configuration frame : extact string from the frame and call DoConfigure ...
Definition: DotConf.cpp:343
const Char_t * GetLastModif() const
Definition: DotConf.h:238
LogMessage fLog
the log messenger ... to know the object hae been properly intitialised/modified
Definition: DotConf.h:100
virtual Bool_t DoConfigure(std::istream &, Bool_t allow_init)
configure this from an input stream
Bool_t IsBeginOfRecord(const std::string &, Bool_t allow_init)
Return true if this string is a begin of record and call Reset if Init is found.
Definition: DotConf.cpp:120
to set informations about the ADF configuration
Base class for a Log message.
Definition: ADFLogMessage.h:80
header file for ADFLogMessage.cpp
virtual Bool_t ProcessLine(const std::string &)
a helper template to do clones : it requires a default constructor. then it uses the Configure facili...
Definition: DotConf.h:216
void SetMaxVersion(Short_t v)
Definition: DotConf.h:176
virtual const Char_t * GetStreamOption() const
get/set option
Definition: DotConf.h:262
virtual void AddConf(DotConf *)
add a conf object to this. The added objects are not owned by this so not deleted.
Definition: DotConf.cpp:222
virtual void SetStreamOption(const Char_t *opt)
Definition: DotConf.h:264
Bool_t IsWithRecord() const
to know if this is intialisased with a stream composed of records.
Definition: DotConf.h:227
Bool_t AddRecord(std::ostream &, char t= 'b')
Add a begin or end of record, return true if done.
Definition: DotConf.cpp:198
void SetWithRecord(Bool_t is_record=true)
to change the behavior
Definition: DotConf.h:230