Laxkit
0.0.7.1
|
Basic building block of entries. More...
Public Member Functions | |
Attribute (const char *nn, const char *nval, const char *nt=NULL) | |
virtual Attribute * | duplicate () |
Return a new deep copy of *this. | |
virtual Attribute * | find (const char *fromname, int *i_ret=NULL) |
Return the first sub-attribute with the name fromname, or NULL if not found. | |
virtual const char * | findValue (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 Attribute * | pushSubAtt (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 char * | dump_in_indented (FILE *f, int indent) |
The opposite of dump_out_indented(). | |
virtual char * | dump_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 | |
char * | name |
char * | atttype |
Laxkit::PtrStack< Attribute > | attributes |
char * | value |
unsigned int | flags |
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.
*** 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)
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.
*** 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().
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.
References dump_in(), LaxFiles::getline_indent_nonblank(), makestr(), and LaxFiles::removeescapes().
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().
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().
|
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().
|
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.
References LaxFiles::dump_out_escaped(), and LaxFiles::dump_out_value().
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().
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().
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().
Push a full blown, already constructed Attribute onto the attribute stack.
If where==-1, then push onto the top of the stack. The calling code must not delete the att. It is now the responsibility of *this.
References push().
Referenced by Laxkit::Button::dump_out_atts(), Laxkit::Palette::dump_out_atts(), Laxkit::DateSelector::dump_out_atts(), Laxkit::MessageBar::dump_out_atts(), Laxkit::Scroller::dump_out_atts(), Laxkit::RulerWindow::dump_out_atts(), Laxkit::anXWindow::dump_out_atts(), duplicate(), LaxFiles::NameValueToAttribute(), Laxkit::FileDialog::newBookmark(), push(), LaxFiles::touch_recently_used(), and LaxFiles::XMLChunkToAttribute().
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.
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.
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.
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.
|
virtual |
Allow for easier pushing of subatts. Push a new one with given name and value, and return pointer to it.
Remove the subattribute with the given index.
Return 0 for succes or 1 for out of range.