Laxkit  0.0.7.1
Public Member Functions | Public Attributes
LaxFiles::Attribute Class Reference

Basic building block of entries. More...

List of all members.

Public Member Functions

 Attribute (const char *nn, const char *nval, const char *nt=NULL)
virtual Attributeduplicate ()
 Return a new deep copy of *this.
virtual Attributefind (const char *fromname, int *i_ret=NULL)
 Return the first sub-attribute with the name fromname, or NULL if not found.
virtual const charfindValue (const char *fromname, int *i_ret=NULL)
 Convenience function to search for a subattribute, and return its value string.
virtual double findDouble (const char *fromname, int *i_ret=NULL)
 Convenience function to search for a subattribute, and convert its value to a double.
virtual AttributepushSubAtt (const char *nname, const char *nvalue=NULL)
virtual int push (Attribute *att, int where)
 Push a full blown, already constructed Attribute onto the attribute stack.
virtual int push (const char *nname)
 Shortcut to push with name and a NULL value to top of stack.
virtual int push (const char *nname, const char *nval, int where=-1)
 Push a simple nname==nval attribute onto this.
virtual int push (const char *nname, long nval, int where=-1)
 Push a simple nname==nval attribute onto this.
virtual int push (const char *nname, int nval, int where=-1)
 Push a simple nname==nval attribute onto this.
virtual int push (const char *nname, double nval, int where=-1)
 Push a simple nname==nval attribute onto this.
virtual int remove (int index)
 Remove the subattribute with the given index.
virtual void clear ()
 Set name, value, atttype to NULL and flush attributes.
virtual int dump_in (const char *filename, Attribute *defines=NULL)
 Read in a whole database.
virtual int dump_in (FILE *f, int Indent, Attribute **stopatsub=NULL)
 Read in sub-attribute data, starting after initial line...
virtual chardump_in_indented (FILE *f, int indent)
 The opposite of dump_out_indented().
virtual chardump_in_until (FILE *f, const char *str, int indent=0)
 Read in until tag is encountered on its own line.
virtual void dump_out (FILE *f, int Indent)
 Write out the subattributes to f, not including this->name/value.
virtual void dump_out_full (FILE *f, int Indent)
 Write out to f.

Public Attributes

charname
charatttype
Laxkit::PtrStack< Attributeattributes
charvalue
unsigned int flags

Detailed Description

Basic building block of entries.

Attributes have a unique name, a particular value, and any number of additional subattributes. They can read and write what I'm calling ida files. Ida standing for 'indented data'. As a result, one is tempted to refer to databases stored in ida files as 'ida know' files.

name is the id tag of the entry, or the attribute name.

atttype is the type of thing that name is. If atttype==NULL, then assume the value is a string.

Todo:

*** make sure that line is being freed where necessary...

most of the dump_in_* and dump_out_* could be put in standalone functions which would be more useful

(note that pangomm and atkmm have an Attribute class, though it is in their own namespace)


Member Function Documentation

int LaxFiles::Attribute::dump_in ( const char filename,
Attribute defines = NULL 
)
virtual

Read in a whole database.

The base is name=file, value=filename.

This currently ignores "define" blocks. This is supposed to offer cascading abilities by following certain rules embodied in the defines, but that is not implemented currently. Each default block changes default values for each entry of that type afterwards in the file. If defines is not NULL, then it is assumed to hold all the relevant definition blocks of the database.

Todo:

*** this function is basically unimplemented.. just opens file, calls the other dump_in. need to implement the defines thingy

*** doesn't do a whole lot of sanity checking on names

*** when dumping in, it is sometimes useful to preserve what the position in the file at which the attribute is written. this would require an extra long variable in Attribute.. For instance for decent error checking, one wants to know where the error occured, but one might still want the ease of dumping in the whole file to an Attribute before parsing values..

Returns 0 for success, otherwise nonzero error.

References makestr().

Referenced by LaxFiles::DumpUtility::dump_in(), LaxInterfaces::GradientDataSpot::dump_in(), dump_in(), LaxInterfaces::SomeData::dump_in(), and Laxkit::anXApp::getlaxrc().

int LaxFiles::Attribute::dump_in ( FILE *  f,
int  Indent,
Attribute **  stopatsub = NULL 
)
virtual

Read in sub-attribute data, starting after initial line...

This function is meant to be called after the line with this->name and value has already been parsed. This function just parses in all the subattributes, and recursively their subattributes. Usually it will be called with Indent equal to 1 more than what this->name/value was indented at. The actual indentation of the subattribute must only be greater than or equal to Indent.

Each subelement parsed in is pushed onto the top of the attributes stack.

If stopatsub!=NULL, then parsing halts after 1 subattribute is encountered, *stopatsub is made to point to the relevant subattribute (which is somewhere on the attributes stack), and the actual indentation of the subattribute line is returned. This allows programs to parse just so far, then they can pass parsing control to their own subelement that corresponds to the current subattribute (the one on the top of the attributes stack) if they so wish. The FILE pointer will point to the beginning of the line following the subattribute name and value.

After this other parsing routine returns, the program can call this function again, and it will continue parsing as if it had just read those subsubattributes. Just be sure that your custom parsing routine advances past all of what may be considered subsubattributes, or else this function will likely think they are furthur subattributes.

In any case, Parsing stops upon the first non-blank, non-comment line that has something at an indentation less than indent.

No substitutions are done. That is, say defaultpage is defined previously in a containing scope, and a subattribute with name defaultpage is found here, it is parsed in as name="defaultpage", value=NULL. Substituting must be done elsewhere.

If stopatsub!=NULL, return -1 for nothing found or EOF, or if a subattribute was just parsed, return the actual indent of that subattribute.

If stopatsub==NULL, return the number of subattributes read, or a negative number for error. The calling code must check for EOF itself. Compounding elements with the +name mechanism counts as 1 subattribute read per +name line.

Todo:
make name==NULL (in file as "") and value=something like "1234\naeuo" behave in some sort of reasonable way, like have name become "" or ~ or something..

References dump_in(), LaxFiles::getline_indent_nonblank(), makestr(), and LaxFiles::removeescapes().

char * LaxFiles::Attribute::dump_in_indented ( FILE *  f,
int  Indent 
)
virtual

The opposite of dump_out_indented().

Lines must be indented >= indent. Blank lines have ".". The first true blank line, or the first lesser indented line stops the reading. Comments are stripped from each line. A comment is anything from an unescaped, unquoted '#' character to the end of the line.

References appendstr(), LaxFiles::getline_indent_nonblank(), and LaxFiles::how_indented().

char * LaxFiles::Attribute::dump_in_until ( FILE *  f,
const char tag,
int  Indent = 0 
)
virtual

Read in until tag is encountered on its own line.

Blank lines need only be blank, they do not have to have the expected indentation. Reading is terminated only by finding tag or eof. Comments are not stripped. The final newline before the tag is not included.

References appendstr(), and LaxFiles::how_indented().

void LaxFiles::Attribute::dump_out ( FILE *  f,
int  indent 
)
virtual

Write out the subattributes to f, not including this->name/value.

Conveniently, you can call dump_out(stdout,0) to dump out the Attribute to the screen.

Please note this does not output this->name and value.

References LaxFiles::dump_out_escaped(), and LaxFiles::dump_out_value().

Referenced by Laxkit::ShortcutManager::dump_out(), and Laxkit::anXWindow::dump_out().

void LaxFiles::Attribute::dump_out_full ( FILE *  f,
int  indent 
)
virtual

Write out to f.

Conveniently, you can call dump_out_full(stdout,0) to dump out the Attribute to the screen.

If there is no name or value, then nothing is written. If name==NULL, then nothing is written for name, but value is still written. This can potentially cause problems when name=NULL and value is something like "1234\naeuo". This will cause a blank line with indent followed by two lines with indent+2: "1234" and "aeuo" beneath it.

Todo:
make name==NULL and value=something like "1234\naeuo" behave in some sort of reasonable way, like have name become "" or ~ or something.. ... null name gets "", but problems still if name has whitespace..

References LaxFiles::dump_out_escaped(), and LaxFiles::dump_out_value().

Attribute * LaxFiles::Attribute::find ( const char fromname,
int i_ret = NULL 
)
virtual

Return the first sub-attribute with the name fromname, or NULL if not found.

If i_ret!=NULL, then fill it with the index of the attribute, if found, or -1 if not found.

Referenced by LaxInterfaces::Path::dump_in_atts(), LaxFiles::recently_used(), Laxkit::anXApp::Resource(), and LaxFiles::touch_recently_used().

double LaxFiles::Attribute::findDouble ( const char fromname,
int i_ret = NULL 
)
virtual

Convenience function to search for a subattribute, and convert its value to a double.

i_ret is the index of the subattribute found, or -1 if not found, or -2 if found, but could not convert to double.

If an attribute is not found, 0 is returned.

References isblank().

const char * LaxFiles::Attribute::findValue ( const char fromname,
int i_ret = NULL 
)
virtual

Convenience function to search for a subattribute, and return its value string.

i_ret is the index of the subattribute found, or -1 if not found, or -2 if found, but could not convert to double.

If an attribute is not found, NULL is returned. If an attribute with a NULL value is found, then "" is returned.

References isblank().

int LaxFiles::Attribute::push ( Attribute att,
int  where 
)
virtual
int LaxFiles::Attribute::push ( const char nname,
const char nval,
int  where = -1 
)
virtual

Push a simple nname==nval attribute onto this.

Note that this simply creates a new Attribute and calls push(Attribute *,int). If where==-1, then push onto the top of the stack.

int LaxFiles::Attribute::push ( const char nname,
long  nval,
int  where = -1 
)
virtual

Push a simple nname==nval attribute onto this.

Note that this simply pushes a new Attribute with name and a string for value equivalent to nval. It calls push(Attribute *,int).

If where==-1, then push onto the top of the stack.

int LaxFiles::Attribute::push ( const char nname,
int  nval,
int  where = -1 
)
virtual

Push a simple nname==nval attribute onto this.

Note that this simply pushes a new Attribute with name and a string for value equivalent to nval. It calls push(Attribute *,int).

If where==-1, then push onto the top of the stack.

int LaxFiles::Attribute::push ( const char nname,
double  nval,
int  where = -1 
)
virtual

Push a simple nname==nval attribute onto this.

Note that this simply pushes a new Attribute with name and a string for value equivalent to nval. It calls push(Attribute *,int).

If where==-1, then push onto the top of the stack.

Attribute * LaxFiles::Attribute::pushSubAtt ( const char nname,
const char nvalue = NULL 
)
virtual

Allow for easier pushing of subatts. Push a new one with given name and value, and return pointer to it.

int LaxFiles::Attribute::remove ( int  index)
virtual

Remove the subattribute with the given index.

Return 0 for succes or 1 for out of range.


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

Mon Feb 17 2014 11:52:58, Laxkit