15.10.2012 - version 0.2.0 - PIIODevice - base of file, ethernet, serial and packets extractor. PIEthernet now support also TCP (client and server). PIConsole now can align labels in each column individually.
This commit is contained in:
23
piconfig.h
Normal file → Executable file
23
piconfig.h
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Config parser
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -54,8 +54,8 @@ class PIConfig: public PIFile
|
||||
friend class Entry;
|
||||
friend class Branch;
|
||||
public:
|
||||
PIConfig(const PIString & path, PIFlags<Mode> mode = Read | Write);
|
||||
~PIConfig() {piForeach (Entry * i, root._children) deleteEntry(i);}
|
||||
PIConfig(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
~PIConfig() {piForeach (Entry * i, root._children) deleteEntry(i); close();}
|
||||
|
||||
class Entry;
|
||||
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
Entry & setValue(const ulong value) {setValue(ultos(value)); setType("n"); return *this;}
|
||||
Entry & setValue(const float value) {setValue(ftos(value)); setType("f"); return *this;}
|
||||
Entry & setValue(const double value) {setValue(dtos(value)); setType("f"); return *this;}
|
||||
|
||||
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exist = 0);
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exist = 0) const {return const_cast<Entry * >(this)->getValue(vname, def, exist);}
|
||||
PICONFIG_GET_VALUE
|
||||
@@ -151,7 +151,8 @@ public:
|
||||
operator PIStringList() {return _value.split("%|%");}
|
||||
|
||||
private:
|
||||
static bool compare(const PIConfig::Entry * f, const PIConfig::Entry * s) {return f->_line < s->_line;}
|
||||
typedef PIConfig::Entry * EntryPtr;
|
||||
static int compare(const EntryPtr * f, const EntryPtr * s) {return (*f)->_line == (*s)->_line ? 0 : (*f)->_line < (*s)->_line ? -1 : 1;}
|
||||
bool entryExists(const Entry * e, const PIString & name) const;
|
||||
void buildLine() {_all = _tab + _full_name + " = " + _value + " #" + _type + " " + _comment;}
|
||||
void clear() {_children.clear(); _name = _value = _type = _comment = _all = PIString(); _line = 0; _parent = 0;}
|
||||
@@ -170,7 +171,7 @@ public:
|
||||
PIString delim;
|
||||
int _line;
|
||||
};
|
||||
|
||||
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exist = 0);
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exist = 0) const {return const_cast<PIConfig * >(this)->getValue(vname, def, exist);}
|
||||
PICONFIG_GET_VALUE
|
||||
@@ -196,26 +197,26 @@ public:
|
||||
bool isEntryExists(const PIString & name) const {return entryExists(&root, name);}
|
||||
|
||||
Branch allTree() {Branch b; piForeach (Entry * i, root._children) b << i; return b;}
|
||||
Branch allLeaves() {Branch b; allLeaves(b, &root); std::sort(b.begin(), b.end(), Entry::compare); return b;}
|
||||
Branch allLeaves() {Branch b; allLeaves(b, &root); b.sort(Entry::compare); return b;}
|
||||
int entryIndex(const PIString & name);
|
||||
|
||||
PIString getName(uint number) {return entryByIndex(number)._name;}
|
||||
PIString getValue(uint number) {return entryByIndex(number)._value;}
|
||||
PIChar getType(uint number) {return entryByIndex(number)._type[0];}
|
||||
PIString getComment(uint number) {return entryByIndex(number)._comment;}
|
||||
|
||||
|
||||
void addEntry(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
||||
void setName(uint number, const PIString & name, bool write = true);
|
||||
void setValue(uint number, const PIString & value, bool write = true);
|
||||
void setType(uint number, const PIString & type, bool write = true);
|
||||
void setComment(uint number, const PIString & comment, bool write = true);
|
||||
|
||||
|
||||
void removeEntry(const PIString & name, bool write = true);
|
||||
void removeEntry(uint number, bool write = true);
|
||||
|
||||
|
||||
void readAll();
|
||||
void writeAll();
|
||||
|
||||
|
||||
const PIString & delimiter() const {return delim;}
|
||||
void setDelimiter(const PIString & d) {delim = d; setEntryDelim(&root, d); readAll();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user