BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
INIFile.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: INIFile.h,v 1.41.20.1 2007/08/09 17:11:53 amoll Exp $
5 //
6 
7 #ifndef BALL_FORMAT_INIFILE_H
8 #define BALL_FORMAT_INIFILE_H
9 
10 #ifndef BALL_DATATYPE_STRINGHASHMAP_H
12 #endif
13 
14 #ifndef BALL_CONCEPT_PROCESSOR_H
15 # include <BALL/CONCEPT/processor.h>
16 #endif
17 
18 namespace BALL
19 {
20  class INIFile;
21 
29  {
30  public:
31 
34  enum
35  {
38  MAX_LINE_LENGTH = 1048576
39  };
40 
41  class IteratorTraits_;
42 
45  {
46  public:
47 
48  friend class INIFile;
49  friend class IteratorTraits_;
50 
52  const String& getName() const
53  {
54  return name_;
55  }
56 
58  bool operator == (const Section& section) const
59  {
60  return (name_ == section.name_ &&
61  lines_ == section.lines_);
62  }
63 
65  bool operator < (const Section& section) const
66  ;
67 
69  bool operator > (const Section& section) const
70  ;
71 
72  protected:
73 
74  // name of the section
76 
77  // all lines of the section
78  std::list<String> lines_;
79 
80  // hashmap with all keys
82  };
83 
85  typedef std::list<Section>::iterator SectionIterator;
86 
92 
96  static const String UNDEFINED;
97 
101  static const String HEADER;
102 
106 
111  INIFile();
112 
116  INIFile(const String& filename);
117 
120  virtual ~INIFile();
121 
126  void clear();
127 
129 
132 
152  bool read();
153 
160  bool write();
161 
164  const String& getFilename() const;
165 
169  void setFilename(const String& filename);
170 
172 
175 
179  bool isValid() const;
180 
182 
189 
198  LineIterator getLine(Size line_number);
199 
201 
205 
215  bool setLine(LineIterator line_it, const String& line);
216 
223  bool deleteLine(LineIterator line_it);
224 
234  bool insertLine(LineIterator line_it, const String& line);
235 
237 
240 
256  bool appendLine(const String& section_name, const String& line);
257 
259  bool appendLine(const String& line);
260 
263  Size getNumberOfLines() const;
264 
271  bool hasSection(const String& section_name) const;
272 
278  SectionIterator getSection(const String& section_name);
279 
284  SectionIterator getSection(Position pos);
285 
289  Size getNumberOfSections() const;
290 
299  LineIterator getSectionFirstLine(const String& section_name);
300 
307  LineIterator getSectionLastLine(const String& section_name);
308 
315  Size getSectionLength(const String& section_name) const;
316 
322  bool deleteSection(const String& section);
323 
327  bool appendSection(const String& section);
328 
330 
333 
341  bool hasEntry(const String& section, const String& key) const;
342 
352  String getValue(const String& section, const String& key) const;
353 
364  bool setValue(const String& section, const String& key, const String& value);
365 
375  bool insertValue(const String& section, const String& key, const String& value);
376 
378  const INIFile& operator = (const INIFile& file)
379  ;
380 
382 
385 
390  bool operator == (const INIFile& inifile) const;
391 
394  bool isValid(const LineIterator& it) const;
395 
398  bool isValid(const SectionIterator& it) const;
399 
401 
404  bool apply(UnaryProcessor<LineIterator>& processor);
405 
408  void setDuplicateKeyCheck(bool mode);
409 
412  bool duplicateKeyCheckEnabled() const;
413 
415  std::list<String> getContent() const
416  ;
417 
419  bool setContent(const std::list<String>& lines)
420  ;
421 
422  protected:
423 
425 
426  bool valid_;
427 
429 
430  // all sections, 0. section is HEADER
431  std::list<Section> sections_;
432 
433  // hashmap with the section names => index
435 
436  public:
437 
440  {
441  friend class INIFile;
442 
443  public:
444 
446 
447 
448  IteratorTraits_();
449 
451  IteratorTraits_(const IteratorTraits_& traits);
452 
454  virtual ~IteratorTraits_();
455 
457  const IteratorTraits_& operator = (const IteratorTraits_ &traits);
458 
460  std::list<String>::iterator getPosition();
461 
463  SectionIterator getSection();
464 
466  const String& operator * () const;
467 
469  IteratorTraits_& operator ++ ();
470 
472  IteratorTraits_& operator -- ();
473 
475  IteratorTraits_& getSectionNextLine();
476 
478  bool operator == (const IteratorTraits_& traits) const;
479 
481  bool operator != (const IteratorTraits_& traits) const;
482 
484  bool operator + () const;
485 
487  bool isValid() const;
488 
490  void toSectionFirstLine();
491 
493  void toSectionLastLine();
494 
496  void toSectionEnd();
497 
499  bool isSectionFirstLine() const;
500 
502  bool isSectionLastLine() const;
503 
505  bool isSectionEnd() const;
506 
508  void toFirstLine();
509 
511  void toLastLine();
512 
514  void toEnd();
515 
516  protected:
517 
518  //_
519  IteratorTraits_(std::list<Section>& list,
520  SectionIterator section,
521  std::list<String>::iterator line);
522 
523  //_
524  const std::list<Section>* getBound_() const;
525 
526  //_
527  void setLine_(const String& line);
528 
529  private:
530 
531  std::list<Section>* bound_;
532  SectionIterator section_;
533  std::list<String>::iterator position_;
534  };
535  };
536 } // namespace BALL
537 
538 #endif // BALL_FORMAT_INIFILE_H
std::list< Section > sections_
Definition: INIFile.h:431
#define BALL_CREATE(name)
Definition: create.h:62
static const String HEADER
Definition: INIFile.h:101
StringHashMap< std::list< String >::iterator > key_map_
Definition: INIFile.h:81
std::list< Section >::iterator SectionIterator
Definition: INIFile.h:85
static const String UNDEFINED
Definition: INIFile.h:96
StringHashMap< SectionIterator > section_index_
Definition: INIFile.h:434
Interface for the LineIterator.
Definition: INIFile.h:439
bool check_duplicate_keys_
Definition: INIFile.h:424
BALL_EXPORT bool operator>(const String &s1, const String &s2)
String filename_
Definition: INIFile.h:428
std::list< String > lines_
Definition: INIFile.h:78
const String & getName() const
Definition: INIFile.h:52
BALL_EXPORT bool operator==(const String &s1, const String &s2)
IteratorTraits_ LineIterator
Definition: INIFile.h:91
bool valid_
Definition: INIFile.h:426
#define BALL_EXPORT
Definition: COMMON/global.h:50
BALL_EXPORT bool operator<(const String &s1, const String &s2)