Loading...
Searching...
No Matches
INIFile.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: INIFile.h,v 1.41.20.1 2007/08/09 17:11:53 amoll Exp $
//
#ifndef BALL_FORMAT_INIFILE_H
#define BALL_FORMAT_INIFILE_H
#ifndef BALL_DATATYPE_STRINGHASHMAP_H
# include <BALL/DATATYPE/stringHashMap.h>
#endif
#ifndef BALL_CONCEPT_PROCESSOR_H
# include <BALL/CONCEPT/processor.h>
#endif
namespace BALL
{
class INIFile;
class BALL_EXPORT INIFile
{
public:
enum
{
MAX_LINE_LENGTH = 1048576
};
class IteratorTraits_;
class BALL_EXPORT Section
{
public:
friend class INIFile;
friend class IteratorTraits_;
const String& getName() const
{
return name_;
}
bool operator == (const Section& section) const
{
return (name_ == section.name_ &&
lines_ == section.lines_);
}
bool operator < (const Section& section) const
;
bool operator > (const Section& section) const
;
protected:
// name of the section
String name_;
// all lines of the section
std::list<String> lines_;
// hashmap with all keys
StringHashMap<std::list<String>::iterator> key_map_;
};
typedef std::list<Section>::iterator SectionIterator;
typedef IteratorTraits_ LineIterator;
static const String UNDEFINED;
static const String HEADER;
INIFile();
INIFile(const String& filename);
virtual ~INIFile();
void clear();
bool read();
bool write();
const String& getFilename() const;
void setFilename(const String& filename);
bool isValid() const;
LineIterator getLine(Size line_number);
bool setLine(LineIterator line_it, const String& line);
bool deleteLine(LineIterator line_it);
bool insertLine(LineIterator line_it, const String& line);
bool appendLine(const String& section_name, const String& line);
bool appendLine(const String& line);
Size getNumberOfLines() const;
bool hasSection(const String& section_name) const;
SectionIterator getSection(const String& section_name);
SectionIterator getSection(Position pos);
Size getNumberOfSections() const;
LineIterator getSectionFirstLine(const String& section_name);
LineIterator getSectionLastLine(const String& section_name);
Size getSectionLength(const String& section_name) const;
bool deleteSection(const String& section);
bool appendSection(const String& section);
bool hasEntry(const String& section, const String& key) const;
String getValue(const String& section, const String& key) const;
bool setValue(const String& section, const String& key, const String& value);
bool insertValue(const String& section, const String& key, const String& value);
const INIFile& operator = (const INIFile& file)
;
bool operator == (const INIFile& inifile) const;
bool isValid(const LineIterator& it) const;
bool isValid(const SectionIterator& it) const;
bool apply(UnaryProcessor<LineIterator>& processor);
void setDuplicateKeyCheck(bool mode);
bool duplicateKeyCheckEnabled() const;
std::list<String> getContent() const
;
bool setContent(const std::list<String>& lines)
;
protected:
bool check_duplicate_keys_;
bool valid_;
String filename_;
// all sections, 0. section is HEADER
std::list<Section> sections_;
// hashmap with the section names => index
StringHashMap<SectionIterator> section_index_;
public:
class BALL_EXPORT IteratorTraits_
{
friend class INIFile;
public:
BALL_CREATE(IteratorTraits_)
IteratorTraits_();
IteratorTraits_(const IteratorTraits_& traits);
virtual ~IteratorTraits_();
const IteratorTraits_& operator = (const IteratorTraits_ &traits);
std::list<String>::iterator getPosition();
SectionIterator getSection();
const String& operator * () const;
IteratorTraits_& operator ++ ();
IteratorTraits_& operator -- ();
IteratorTraits_& getSectionNextLine();
bool operator == (const IteratorTraits_& traits) const;
bool operator != (const IteratorTraits_& traits) const;
bool operator + () const;
bool isValid() const;
void toSectionFirstLine();
void toSectionLastLine();
void toSectionEnd();
bool isSectionFirstLine() const;
bool isSectionLastLine() const;
bool isSectionEnd() const;
void toFirstLine();
void toLastLine();
void toEnd();
protected:
//_
IteratorTraits_(std::list<Section>& list,
SectionIterator section,
std::list<String>::iterator line);
//_
const std::list<Section>* getBound_() const;
//_
void setLine_(const String& line);
private:
std::list<Section>* bound_;
SectionIterator section_;
std::list<String>::iterator position_;
};
};
} // namespace BALL
#endif // BALL_FORMAT_INIFILE_H
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::INIFile::IteratorTraits_
Interface for the LineIterator.
Definition INIFile.h:440
BALL::INIFile::IteratorTraits_::isValid
bool isValid() const
BALL::INIFile::IteratorTraits_::toSectionFirstLine
void toSectionFirstLine()
BALL::INIFile::IteratorTraits_::INIFile
friend class INIFile
Definition INIFile.h:441
BALL::INIFile::IteratorTraits_::toSectionLastLine
void toSectionLastLine()
BALL::INIFile::IteratorTraits_::isSectionEnd
bool isSectionEnd() const
BALL::INIFile::IteratorTraits_::setLine_
void setLine_(const String &line)
BALL::INIFile::IteratorTraits_::toFirstLine
void toFirstLine()
BALL::INIFile::IteratorTraits_::toLastLine
void toLastLine()
BALL::INIFile::IteratorTraits_::isSectionFirstLine
bool isSectionFirstLine() const
BALL::INIFile::IteratorTraits_::getSectionNextLine
IteratorTraits_ & getSectionNextLine()
BALL::INIFile::IteratorTraits_::getBound_
const std::list< Section > * getBound_() const
BALL::INIFile::IteratorTraits_::toEnd
void toEnd()
BALL::INIFile::IteratorTraits_::toSectionEnd
void toSectionEnd()
BALL::INIFile::IteratorTraits_::getPosition
std::list< String >::iterator getPosition()
BALL::INIFile::IteratorTraits_::IteratorTraits_
IteratorTraits_()
BALL::INIFile::IteratorTraits_::isSectionLastLine
bool isSectionLastLine() const
BALL::INIFile::IteratorTraits_::getSection
SectionIterator getSection()
BALL::INIFile::Section
Definition INIFile.h:45
BALL::INIFile::Section::key_map_
StringHashMap< std::list< String >::iterator > key_map_
Definition INIFile.h:81
BALL::INIFile::Section::name_
String name_
Definition INIFile.h:75
BALL::INIFile::Section::INIFile
friend class INIFile
Definition INIFile.h:48
BALL::INIFile::Section::lines_
std::list< String > lines_
Definition INIFile.h:78
BALL::INIFile::Section::IteratorTraits_
friend class IteratorTraits_
Definition INIFile.h:49
BALL::INIFile::Section::getName
const String & getName() const
Definition INIFile.h:52
BALL::INIFile
Definition INIFile.h:29
BALL::INIFile::getSectionLength
Size getSectionLength(const String &section_name) const
BALL::INIFile::duplicateKeyCheckEnabled
bool duplicateKeyCheckEnabled() const
BALL::INIFile::appendSection
bool appendSection(const String &section)
BALL::INIFile::SectionIterator
std::list< Section >::iterator SectionIterator
Definition INIFile.h:85
BALL::INIFile::insertLine
bool insertLine(LineIterator line_it, const String &line)
BALL::INIFile::getSectionLastLine
LineIterator getSectionLastLine(const String &section_name)
BALL::INIFile::isValid
bool isValid(const LineIterator &it) const
BALL::INIFile::read
bool read()
BALL::INIFile::setLine
bool setLine(LineIterator line_it, const String &line)
BALL::INIFile::getSection
SectionIterator getSection(const String &section_name)
BALL::INIFile::deleteSection
bool deleteSection(const String &section)
BALL::INIFile::section_index_
StringHashMap< SectionIterator > section_index_
Definition INIFile.h:434
BALL::INIFile::setDuplicateKeyCheck
void setDuplicateKeyCheck(bool mode)
BALL::INIFile::getSectionFirstLine
LineIterator getSectionFirstLine(const String &section_name)
BALL::INIFile::clear
void clear()
BALL::INIFile::write
bool write()
BALL::INIFile::deleteLine
bool deleteLine(LineIterator line_it)
BALL::INIFile::appendLine
bool appendLine(const String &line)
Append a line to the last section.
BALL::INIFile::HEADER
static const String HEADER
Definition INIFile.h:101
BALL::INIFile::filename_
String filename_
Definition INIFile.h:428
BALL::INIFile::getContent
std::list< String > getContent() const
BALL::INIFile::hasSection
bool hasSection(const String &section_name) const
BALL::INIFile::appendLine
bool appendLine(const String &section_name, const String &line)
BALL::INIFile::LineIterator
IteratorTraits_ LineIterator
Definition INIFile.h:91
BALL::INIFile::getNumberOfLines
Size getNumberOfLines() const
BALL::INIFile::getLine
LineIterator getLine(Size line_number)
BALL::INIFile::UNDEFINED
static const String UNDEFINED
Definition INIFile.h:96
BALL::INIFile::INIFile
INIFile(const String &filename)
BALL::INIFile::isValid
bool isValid() const
BALL::INIFile::setFilename
void setFilename(const String &filename)
BALL::INIFile::getNumberOfSections
Size getNumberOfSections() const
BALL::INIFile::MAX_LINE_LENGTH
@ MAX_LINE_LENGTH
Definition INIFile.h:38
BALL::INIFile::isValid
bool isValid(const SectionIterator &it) const
BALL::INIFile::sections_
std::list< Section > sections_
Definition INIFile.h:431
BALL::INIFile::setContent
bool setContent(const std::list< String > &lines)
BALL::INIFile::getSection
SectionIterator getSection(Position pos)
BALL::INIFile::check_duplicate_keys_
bool check_duplicate_keys_
Definition INIFile.h:424
BALL::INIFile::INIFile
INIFile()
BALL::INIFile::getValue
String getValue(const String &section, const String &key) const
BALL::INIFile::apply
bool apply(UnaryProcessor< LineIterator > &processor)
BALL::INIFile::valid_
bool valid_
Definition INIFile.h:426
BALL::INIFile::getFilename
const String & getFilename() const
BALL::INIFile::~INIFile
virtual ~INIFile()
BALL::INIFile::insertValue
bool insertValue(const String &section, const String &key, const String &value)
BALL::INIFile::setValue
bool setValue(const String &section, const String &key, const String &value)
BALL::INIFile::hasEntry
bool hasEntry(const String &section, const String &key) const
BALL::StringHashMap
Definition stringHashMap.h:42
BALL::String
Definition string.h:57
BALL::UnaryProcessor
Definition processor.h:60
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
std
STL namespace.
processor.h
stringHashMap.h