OFFIS DCMTK  Version 3.6.0
ofconfig.h
1 /*
2  *
3  * Copyright (C) 1997-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: ofstd
15  *
16  * Author: Marco Eichelberg
17  *
18  * Purpose:
19  * classes: OFConfigFile
20  *
21  * Last Update: $Author: joergr $
22  * Update Date: $Date: 2010-10-14 13:15:50 $
23  * CVS/RCS Revision: $Revision: 1.8 $
24  * Status: $State: Exp $
25  *
26  * CVS/RCS Log at end of file
27  *
28  */
29 
30 #ifndef OFCONFIG_H
31 #define OFCONFIG_H
32 
33 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
34 #include "dcmtk/ofstd/ofstring.h"
35 #include "dcmtk/ofstd/ofstack.h"
36 #include "dcmtk/ofstd/ofstream.h"
37 
38 #define INCLUDE_CSTDIO
39 #include "dcmtk/ofstd/ofstdinc.h"
40 
41 /*
42  * Short description of configuration file structure:
43  * - The data in a configuration file have a tree structure.
44  * The tree has a depth defined at instantiation time (by default, OFConfigFile_MaxLevel),
45  * not including the (imaginary) root node.
46  * - A level 0 entry (a leaf) has the form: KEYWORD = VALUE,
47  * where the keyword starts on row one of a line.
48  * - A level 1 entry has the form [KEYWORD]
49  * - A level 2 entry has the form [[KEYWORD]] (and so on).
50  * - Keywords may consist of:
51  * A..Z, a..z (which are converted to uppercase),
52  * 0..9,
53  * '-'
54  * - Values can be any kind of ASCII text. Values may span multiple lines.
55  * To continue a value in the next line, the next line MUST start with
56  * (any amount of) whitespace, which is discarded when reading the value.
57  * linefeeds (converted to ASCII 10 if necessary) are kept in the
58  * value string. Empty lines are discarded (and also their linefeed).
59  * - The data must have a "clean" tree structure. This means that there
60  * MUST be a level 2 keyword before any level 1 keyword etc.
61  * - lines starting with the comment char (default is "#") are interpreted
62  * as comment lines.
63  *
64  */
65 
66 #define OFConfigFile_MaxLevel 2
67 #define OFConfigFile_CommentChar '#'
68 
69 class OFConfigFile;
70 class OFConfigFileNode;
71 
73 
74 
80 {
81 public:
85  OFConfigFileNode(const char *keyword);
86 
89 
92  const char *getKeyword() const
93  {
94  return keyword_.c_str();
95  }
96 
99  const char *getValue() const
100  {
101  return value_.c_str();
102  }
103 
107  void setValue(const char *c)
108  {
109  value_ = c;
110  }
111 
116  OFBool match(const char *c) const
117  {
118  return (keyword_ == c);
119  }
120 
125  OFBool less(const char *c) const
126  {
127  return (keyword_ < c);
128  }
129 
134  {
135  return brother_;
136  }
137 
142  {
143  return son_;
144  }
145 
150  {
151  brother_ = brother;
152  }
153 
158  {
159  son_ = son;
160  }
161 
166  void print(STD_NAMESPACE ostream& out, unsigned int level);
167 
168 private:
171 
174 
177 
180 
183 
186 };
187 
190 
195 {
196 public:
199  OFConfigFileCursor(unsigned int maxLevel)
200  : array_(NULL)
201  , maxLevel_(maxLevel)
202  {
203  clear();
204  }
205 
208  OFConfigFileCursor(const OFConfigFileCursor& source);
209 
213  {
214  delete[] array_;
215  }
216 
220 
222  void clear();
223 
228  const char *getKeyword(unsigned int level) const
229  {
230  if ((level <= maxLevel_) && array_ && array_[level]) return array_[level]->getKeyword(); else return NULL;
231  }
232 
237  const char *getValue(unsigned int level) const
238  {
239  if ((level <= maxLevel_) && array_ && array_[level]) return array_[level]->getValue(); else return NULL;
240  }
241 
247  OFBool section_valid(unsigned int level) const;
248 
259  void set_section(
260  unsigned int level,
261  const char *key,
262  OFConfigFileNode *anchor);
263 
273  void first_section(
274  unsigned int level,
275  OFConfigFileNode *anchor);
276 
285  void next_section(unsigned int level);
286 
294  void insert(
295  unsigned int level,
296  OFConfigFileNode *& newnode,
297  OFConfigFileNode *& anchor,
298  OFBool orderedMode);
299 
303  OFBool operator<(const OFConfigFileCursor& /* arg */) const
304  {
305  return OFFalse;
306  }
307 
311  OFBool operator==(const OFConfigFileCursor& /* arg */) const
312  {
313  return OFTrue;
314  }
315 
316 private:
317 
325  void orderedInsert(
326  OFConfigFileNode *parent,
327  OFConfigFileNode *&newnode);
328 
331 
333  unsigned int maxLevel_;
334 };
335 
336 
343 {
344 public:
345 
353  OFConfigFile(
354  FILE *infile,
355  unsigned int maxLevel = OFConfigFile_MaxLevel,
356  char commentChar = OFConfigFile_CommentChar,
357  OFBool orderedMode = OFFalse);
358 
361  virtual ~OFConfigFile();
362 
366  void loadFile(FILE *infile);
367 
373  const char *get_keyword(unsigned int level);
374 
379  const char *get_value();
380 
391  OFBool get_bool_value(OFBool defaultvalue);
392 
398  OFBool section_valid(unsigned int level) const
399  {
400  return cursor_.section_valid(level);
401  }
402 
412  void set_section(unsigned int level, const char *key)
413  {
414  cursor_.set_section(level, key, anchor_);
415  }
416 
425  void first_section(unsigned int level)
426  {
427  cursor_.first_section(level, anchor_);
428  }
429 
438  void next_section(unsigned int level)
439  {
440  cursor_.next_section(level);
441  }
442 
445  void save_cursor();
446 
449  void restore_cursor();
450 
459  void select_section(
460  const char *key1,
461  const char *key2=NULL,
462  const char *key3=NULL);
463 
469  const char *get_entry(const char *key0);
470 
474  void print(STD_NAMESPACE ostream& out);
475 
476 private:
477 
484  char read_char(FILE *infile);
485 
491  char read_keywordchar(FILE *infile);
492 
499  void read_entry(FILE *infile);
500 
505  void store_char(char c);
506 
509  OFConfigFile(const OFConfigFile&);
510 
514 
515 
518 
521 
524 
527 
529  int crfound_;
530 
532  char *buffer_;
533 
535  size_t bufptr_;
536 
538  long bufsize_;
539 
541  unsigned int maxLevel_;
542 
545 
555  OFBool orderedMode_;
556 };
557 
558 #endif
559 
560 /*
561  * $Log: ofconfig.h,v $
562  * Revision 1.8 2010-10-14 13:15:50 joergr
563  * Updated copyright header. Added reference to COPYRIGHT file.
564  *
565  * Revision 1.7 2010-04-26 12:22:30 uli
566  * Fixed a some minor doxygen warnings.
567  *
568  * Revision 1.6 2008-04-16 09:37:27 meichel
569  * class OFConfigFile now supports an ordered mode where multiple
570  * configuration files can be loaded and can replace entries of other.
571  * Also added function to print content of configuration in reloadable format.
572  *
573  * Revision 1.5 2008-04-15 15:46:30 meichel
574  * class OFConfigFile now supports flexible tree depths and configurable
575  * comment characters and can, therefore, fully replace the equivalent
576  * code in module dcmprint.
577  *
578  * Revision 1.4 2005/12/08 16:05:51 meichel
579  * Changed include path schema for all DCMTK header files
580  *
581  * Revision 1.3 2003/06/12 13:15:59 joergr
582  * Fixed inconsistent API documentation reported by Doxygen.
583  *
584  * Revision 1.2 2003/06/04 12:31:44 meichel
585  * Added dummy comparison operators, needed by MSVC5 with STL
586  *
587  * Revision 1.1 2003/04/29 10:14:16 meichel
588  * Moved configuration file parser from module dcmpstat to ofstd and renamed
589  * class to OFConfigFile. Cleaned up implementation (no more friend declarations).
590  *
591  *
592  */
593 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2