yast2-core
Public Member Functions | Private Member Functions | Private Attributes | List of all members
IniSection Class Reference

#include <IniFile.h>

Inheritance diagram for IniSection:
IniBase

Public Member Functions

 IniSection (const char *u)
 
 IniSection (const IniParser *p)
 
 IniSection (const IniSection &s)
 
void operator= (const IniSection &s)
 
virtual ~IniSection ()
 
 IniSection (const IniParser *p, string n)
 
void initValue (const string &key, const string &val, const string &comment, int rb)
 
IniSectioninitSection (const string &name, const string &comment, int rb, int wb=-2)
 
void initReadBy ()
 
void setRewriteBy (int c)
 
int getRewriteBy ()
 
int getSubSectionRewriteBy (const char *name)
 
void setPrivate (bool p)
 
bool isPrivate () const
 
void setEndComment (const char *c)
 
const char * getEndComment () const
 
bool isDirty ()
 
virtual void clean ()
 
IniSectionfindSection (const vector< string > &path, int from=0)
 
int findEndFromUp (const vector< string > &path, int wanted, int found=-1, int from=0)
 
void Dump ()
 
int Read (const YCPPath &p, YCPValue &out, bool rewrite)
 
int Dir (const YCPPath &p, YCPList &out)
 
int Write (const YCPPath &p, const YCPValue &v, bool rewrite)
 
int Delete (const YCPPath &p)
 
IniIterator getContainerBegin ()
 
IniIterator getContainerEnd ()
 
IniSectiongetSection (const char *name)
 
- Public Member Functions inherited from IniBase
virtual ~IniBase ()
 
const char * getName () const
 
const char * getComment () const
 
int getReadBy () const
 
void setName (const string &c)
 
void setComment (const string &c)
 
void setReadBy (int r)
 
void setDirty ()
 
void initName (const string &c)
 
void initComment (const string &c)
 
void initReadBy (const int r)
 
void init (const string &n, const string &c, int rb)
 

Private Member Functions

void reindex ()
 
int getMyValue (const YCPPath &p, YCPValue &out, int what, int depth)
 
int getValue (const YCPPath &p, YCPValue &out, int what, int depth=0)
 
int getSectionProp (const YCPPath &p, YCPValue &out, int what, int depth=0)
 
int getAll (const YCPPath &p, YCPValue &out, int depth)
 
YCPMap getAllDoIt ()
 
int myDir (YCPList &l, IniType what)
 
int dirHelper (const YCPPath &p, YCPList &out, int sections, int depth=0)
 
int setMyValue (const YCPPath &p, const YCPValue &in, int what, int depth)
 
int setValue (const YCPPath &p, const YCPValue &in, int what, int depth=0)
 
int setSectionProp (const YCPPath &p, const YCPValue &in, int what, int depth)
 
int setAll (const YCPPath &p, const YCPValue &in, int depth)
 
int setAllDoIt (const YCPMap &in)
 
int delValue (const YCPPath &p, int depth)
 
int delSection (const YCPPath &p, int depth)
 
void delMyValue (const string &k)
 
void delValue1 (IniEntryIdxIterator exi)
 
void delSection1 (IniSectionIdxIterator sxi)
 
int getValueFlat (const YCPPath &p, YCPValue &out)
 
int setValueFlat (const YCPPath &p, const YCPValue &in)
 
int delValueFlat (const YCPPath &p)
 
int dirValueFlat (const YCPPath &p, YCPList &l)
 

Private Attributes

const IniParserip
 
string end_comment
 
bool is_private
 
int rewrite_by
 
IniContainer container
 
IniEntryIndex ivalues
 
IniSectionIndex isections
 

Additional Inherited Members

- Protected Member Functions inherited from IniBase
 IniBase (int rb)
 
 IniBase (const string &n)
 
bool getMapString (const YCPMap &in, const string &k, string &s)
 helper for setAllDoIt More...
 
bool getMapInteger (const YCPMap &in, const string &k, int &i)
 helper for setAllDoIt More...
 
- Protected Attributes inherited from IniBase
string name
 
string comment
 
int read_by
 
bool dirty
 

Detailed Description

Section definition.

Constructor & Destructor Documentation

IniSection::IniSection ( const char *  u)
inline

explicit uninitialized constructor

IniSection::IniSection ( const IniParser p)
inline
IniSection::IniSection ( const IniSection s)
inline

Must define an own copy constructor so that the indices point to the copy, not the original

References reindex().

virtual IniSection::~IniSection ( )
inlinevirtual
IniSection::IniSection ( const IniParser p,
string  n 
)
inline

this is a constructor for newly added sections –> sets dirty

Parameters
ipparser to take options from
nname of section

Member Function Documentation

void IniSection::clean ( )
virtual

set all subsection and values to clean

Reimplemented from IniBase.

References container, IniBase::dirty, and SECTION.

Referenced by IniAgent::Write(), and IniParser::write_helper().

int IniSection::Delete ( const YCPPath p)

Generic delete for values, sections.

Parameters
ppath to delete
Returns
0: success

References delSection(), delValue(), delValueFlat(), ip, IniParser::isFlat(), and y2error.

Referenced by IniAgent::Write().

void IniSection::delMyValue ( const string &  k)
private

deletes all values of this name we own

Parameters
knormalized key

References delValue1(), ivalues, and y2debug.

Referenced by delValue(), and delValueFlat().

int IniSection::delSection ( const YCPPath p,
int  depth 
)
private

Delete section on path. Deletes also all its subsections.

Parameters
ppath to delete value at
depthsee getSectionProp
Returns
0 in case of success

References IniParser::changeCase(), delSection(), delSection1(), ip, isections, y2debug, and y2error.

Referenced by Delete(), and delSection().

void IniSection::delSection1 ( IniSectionIdxIterator  sxi)
private

deletes a section we own

References container, IniBase::dirty, and isections.

Referenced by delSection(), and setSectionProp().

int IniSection::delValue ( const YCPPath p,
int  depth 
)
private

Delete value on path

Parameters
ppath to delete value at
depthsee getSectionProp
Returns
0 in case of success

References IniParser::changeCase(), delMyValue(), delValue(), ip, isections, and y2error.

Referenced by Delete(), and delValue().

void IniSection::delValue1 ( IniEntryIdxIterator  exi)
private

deletes a section we own

References container, IniBase::dirty, and ivalues.

Referenced by delMyValue(), and setMyValue().

int IniSection::delValueFlat ( const YCPPath p)
private

Delete value in flat mode

References IniParser::changeCase(), delMyValue(), and ip.

Referenced by Delete().

int IniSection::Dir ( const YCPPath p,
YCPList out 
)

Generic interface to SCR::Dir

References YCPList::add(), dirHelper(), dirValueFlat(), ip, IniParser::isFlat(), and y2error.

Referenced by IniAgent::Dir().

int IniSection::dirHelper ( const YCPPath p,
YCPList out,
int  sections,
int  depth = 0 
)
private

Recursive function to find the one section we want to dir and at last to do dir.

Parameters
ppath
outlist of sections/keys
sectionsget sections (0) or values (!0)?
depthsee getSectionProp
Returns
0 in case of success

References IniParser::changeCase(), dirHelper(), ip, isections, myDir(), SECTION, VALUE, and y2debug.

Referenced by Dir(), and dirHelper().

int IniSection::dirValueFlat ( const YCPPath p,
YCPList l 
)
private

Get list of values in flat mode.

References myDir(), and VALUE.

Referenced by Dir().

void IniSection::Dump ( )
int IniSection::findEndFromUp ( const vector< string > &  path,
int  wanted,
int  found = -1,
int  from = 0 
)

OBSOLETE, to be removed. If currently parsed end-section-tag hasn't matched currently processed section by name, we need to find the best possible match by type (read_by). Hence we look for a section on current path which can be closed by found end-section-tag. Note: this function can abort if the path passed in invalid.

Parameters
pathstack of the sections
wantedread-by we want to find
foundlet unset, last path index that matched
fromlet unset, current path index
Returns
index to path

References IniParser::changeCase(), findEndFromUp(), ip, isections, IniBase::read_by, and y2error.

Referenced by findEndFromUp().

IniSection & IniSection::findSection ( const vector< string > &  path,
int  from = 0 
)

OBSOLETE, to be removed. Gets section on a path. Recursive. Attention! This function aborts when it doesn't find the section! Use with care! (Used only by IniParser::parse_helper)

Parameters
pathpath to the section
fromrecursion depth
Returns
Found ini section iterator

References IniParser::changeCase(), findSection(), ip, isections, and y2error.

Referenced by findSection().

int IniSection::getAll ( const YCPPath p,
YCPValue out,
int  depth 
)
private

Get a complete subtree

Parameters
ppath : .all or .all.sec1.sec2
outoutput is placed here
depthIndex of current path component. This function is recursive and depth marks the depth of recursion. We look for path[depth] in current "scope"
Returns
0 in case of success

References IniParser::changeCase(), getAllDoIt(), ip, isections, and y2error.

Referenced by Read().

YCPMap IniSection::getAllDoIt ( )
privatevirtual

Gets data for this section and all its values and subsections

Reimplemented from IniBase.

References YCPMap::add(), YCPList::add(), IniBase::getAllDoIt(), getContainerBegin(), getContainerEnd(), rewrite_by, and VALUE.

Referenced by getAll().

IniIterator IniSection::getContainerBegin ( )
IniIterator IniSection::getContainerEnd ( )
const char* IniSection::getEndComment ( ) const
inline

References end_comment.

Referenced by IniParser::write_helper().

int IniSection::getMyValue ( const YCPPath p,
YCPValue out,
int  what,
int  depth 
)
private

Get a value (or list of them if repeat_names) in this section It would be enough to pass only k instead of p and depth, but then the error messages would not know the whole path

Parameters
ppath
outoutput is placed here as YCPString or YCPInteger
what0 - value, 1 - comment, other - read-by
depthpath index
Returns
0 in case of success

References YCPList::add(), IniParser::changeCase(), IniBase::getComment(), IniBase::getReadBy(), IniEntry::getValue(), ip, ivalues, IniParser::repeatNames(), and y2debug.

Referenced by getValue(), and getValueFlat().

int IniSection::getRewriteBy ( )
inline

References rewrite_by.

Referenced by IniParser::write().

IniSection & IniSection::getSection ( const char *  name)

Aborts if entry doesn't exist!

Parameters
namename of the entry to get
Returns
entry Aborts if section doesn't exist! TODO gets any of multiple sections
Parameters
namename of the section to get
Returns
section

References isections, IniBase::name, and y2error.

int IniSection::getSectionProp ( const YCPPath p,
YCPValue out,
int  what,
int  depth = 0 
)
private

Get section property – comment or read-by

Parameters
ppath to value: .section_commment.sec1.sec2.sec3
outoutput is placed here as YCPString or YCPInteger
what0 - comment, 1 - rewrite_by, other - read-by
depthIndex of current path component. This function is recursive and depth marks the depth of recursion. We look for path[depth] in current "scope"
Returns
0 in case of success

References YCPList::add(), IniParser::changeCase(), IniBase::comment, getSectionProp(), ip, isections, IniBase::read_by, IniParser::repeatNames(), rewrite_by, and y2debug.

Referenced by getSectionProp(), and Read().

int IniSection::getSubSectionRewriteBy ( const char *  name)
Parameters
namename of a section
Returns
rewrite-by of section or -1 if the section wasn't found

References isections.

Referenced by IniAgent::Write().

int IniSection::getValue ( const YCPPath p,
YCPValue out,
int  what,
int  depth = 0 
)
private

Get a value on a path

Parameters
ppath to value: .value.sec1.sec2.key
outoutput is placed here as YCPString or YCPInteger
what0 - value, 1 - comment, other - read-by
depthIndex of current path component. This function is recursive and depth marks the depth of recursion. We look for path[depth] in current "scope"
Returns
0 in case of success

References IniParser::changeCase(), getMyValue(), ip, isections, and y2debug.

Referenced by Read().

int IniSection::getValueFlat ( const YCPPath p,
YCPValue out 
)
private

Get value in flat mode.

Parameters
ppath to value
outoutput
Returns
0 in case of success

References IniParser::changeCase(), getMyValue(), and ip.

Referenced by Read().

void IniSection::initReadBy ( )
inline

This function has very special purpose, it ensures that top-section delimiter is not written when saving multiple files.

References IniBase::read_by.

Referenced by IniParser::write().

IniSection & IniSection::initSection ( const string &  name,
const string &  comment,
int  rb,
int  wb = -2 
)

If section already exist, it is updated only in case, that it isn't dirty.

Parameters
namesection name
commentcomment
rbread-by
wbrewrite-by. if -2 (default), it is not changed
Returns
a reference to the section

References IniParser::changeCase(), IniBase::comment, container, IniBase::dirty, ip, isections, IniBase::name, IniBase::read_by, IniParser::repeatNames(), and rewrite_by.

Referenced by IniParser::parse_helper().

void IniSection::initValue ( const string &  key,
const string &  val,
const string &  comment,
int  rb 
)

If value doesn't exist, creates new, otherwise calls method init of the existing one.

Parameters
keykey
valvalue
commentcomment
rbread-by

References IniParser::changeCase(), container, IniEntry::init(), ip, ivalues, and IniParser::repeatNames().

Referenced by IniParser::parse_helper().

bool IniSection::isDirty ( )

References IniBase::dirty, and isections.

Referenced by IniParser::write().

bool IniSection::isPrivate ( ) const
inline

References is_private.

Referenced by IniParser::write_file().

int IniSection::myDir ( YCPList l,
IniType  what 
)
private

Get directory of this section

Parameters
lresult list
whatVALUE or SECTION
Returns
0 in case of success

References YCPList::add(), container, and SECTION.

Referenced by dirHelper(), and dirValueFlat().

void IniSection::operator= ( const IniSection s)
inline
int IniSection::Read ( const YCPPath p,
YCPValue out,
bool  rewrite 
)

Generic interface to SCR::Read

Parameters
rewritea #19066 hack - if rewriting is active, .st accesses rewrite_by

References getAll(), getSectionProp(), getValue(), getValueFlat(), ip, IniParser::isFlat(), and y2error.

Referenced by IniAgent::Read().

void IniSection::reindex ( )
private

build ivalues and isections

References IniParser::changeCase(), getContainerBegin(), getContainerEnd(), ip, isections, ivalues, and VALUE.

Referenced by IniSection(), operator=(), and setAllDoIt().

int IniSection::setAll ( const YCPPath p,
const YCPValue in,
int  depth 
)
private

Set all properties and values for a section. No recursive creation of the specified path.

Parameters
ppath where to start
invalue to set
depthsee getSectionProp
Returns
0 in case of success

References IniParser::changeCase(), ip, isections, setAllDoIt(), and y2debug.

Referenced by Write().

int IniSection::setAllDoIt ( const YCPMap in)
privatevirtual

Set all properties and values for a section.

Parameters
invalue to set
Returns
0 in case of success

Reimplemented from IniBase.

References container, IniParser::getFileName(), IniBase::getMapInteger(), IniBase::getMapString(), ip, YCPElement::isNull(), reindex(), rewrite_by, IniBase::setAllDoIt(), IniEntry::setAllDoIt(), setAllDoIt(), YCPList::size(), YCPMap::value(), YCPList::value(), and y2error.

Referenced by setAll(), and setAllDoIt().

void IniSection::setEndComment ( const char *  c)

If there is no comment at the beginning and no values and no sections, it is better to set is as comment at the beginning. Sets also dirty flag.

Parameters
ccomment

References IniBase::comment, container, and end_comment.

Referenced by IniParser::parse_helper().

int IniSection::setMyValue ( const YCPPath p,
const YCPValue in,
int  what,
int  depth 
)
private

Set a value (or list of them if repeat_names) in this section It would be enough to pass only k instead of p and depth, but then the error messages would not know the whole path

Parameters
ppath
invalue to set (YCPString or YCPInteger) (or YCPList)
what0 – value, 1 – comment, other – read-by.
depthpath index
Returns
0 on success

need to add a value ...

References YCPList::add(), as_integer(), as_list(), as_string(), IniParser::changeCase(), container, delValue1(), IniBase::dirty, ip, YCPElement::isNull(), ivalues, IniParser::repeatNames(), IniBase::setComment(), IniBase::setName(), IniBase::setReadBy(), IniEntry::setValue(), YCPList::size(), to_string(), YCPList::value(), y2debug, and y2error.

Referenced by setValue(), and setValueFlat().

void IniSection::setPrivate ( bool  p)
inline

References is_private.

Referenced by setSectionProp().

void IniSection::setRewriteBy ( int  c)
inline

sets dirty flag also

References IniBase::dirty, and rewrite_by.

Referenced by setSectionProp().

int IniSection::setSectionProp ( const YCPPath p,
const YCPValue in,
int  what,
int  depth 
)
private

Set section comment or read-by. Creates recursively all non-existing subsections.

Parameters
ppath to set value on
invalue to set (YCPString or YCPInteger)
what0 – comment, 1 - rewrite_by, other – read-by.
depthsee getSectionProp
Returns
0

need to add a section ...

References YCPList::add(), as_boolean(), as_integer(), as_list(), as_string(), IniParser::changeCase(), container, delSection1(), ip, isections, YCPElement::isNull(), IniParser::repeatNames(), IniBase::setComment(), setPrivate(), IniBase::setReadBy(), setRewriteBy(), YCPList::size(), str, YCPList::value(), and y2debug.

Referenced by Write().

int IniSection::setValue ( const YCPPath p,
const YCPValue in,
int  what,
int  depth = 0 
)
private

Set value on path. Creates recursively all non-existing subsections.

Parameters
ppath to set value on
invalue to set (YCPString or YCPInteger)
what0 – value, 1 – comment, other – read-by.
depthsee getSectionProp
Returns
0

References IniParser::changeCase(), container, ip, isections, setMyValue(), and y2debug.

Referenced by Write().

int IniSection::setValueFlat ( const YCPPath p,
const YCPValue in 
)
private

Set value in flat mode.

Parameters
ppath to value
outinput
Returns
0 in case of success

References IniParser::changeCase(), ip, and setMyValue().

Referenced by Write().

int IniSection::Write ( const YCPPath p,
const YCPValue v,
bool  rewrite 
)

Generic interface to SCR::Write

Parameters
rewritea #19066 hack - if rewriting is active, .st accesses rewrite_by

References ip, IniParser::isFlat(), setAll(), setSectionProp(), setValue(), setValueFlat(), and y2error.

Referenced by IniAgent::Write().

Member Data Documentation

IniContainer IniSection::container
private

What entries of cvalues and csections are valid Values contained by this section Sections contained by this section

Referenced by clean(), delSection1(), delValue1(), getContainerBegin(), getContainerEnd(), initSection(), initValue(), myDir(), operator=(), setAllDoIt(), setEndComment(), setMyValue(), setSectionProp(), and setValue().

string IniSection::end_comment
private

if this is global section, there may be comment at the end this is quite special case, it is impossible to change it

Referenced by getEndComment(), operator=(), and setEndComment().

const IniParser* IniSection::ip
private
bool IniSection::is_private
private

It is effective only when the section corresponds to a file. The file will not be readable by group and others. bnc#713661

Referenced by isPrivate(), operator=(), and setPrivate().

IniSectionIndex IniSection::isections
private
IniEntryIndex IniSection::ivalues
private

Index of values

Referenced by delMyValue(), delValue1(), Dump(), getMyValue(), initValue(), reindex(), and setMyValue().

int IniSection::rewrite_by
private

index to IniParser::rewrites for filename - section name mapping It appears that read_by was used for both purposes, causing bug (#19066).

Referenced by getAllDoIt(), getRewriteBy(), getSectionProp(), initSection(), operator=(), setAllDoIt(), and setRewriteBy().


The documentation for this class was generated from the following files:

Generated on a sunny day for yast2-core by doxygen 1.8.5