| XmlConfig (QString file, int mode=IO_ReadOnly)
|
XmlConfig |
CONSTRUCTOR We make the xml document from the file. So we can close the file, we have all the info in doc, we only deal with Xml clases from now on.
Parameters:
| file | File we read the XML from , if the file can't be read or it's not a valid XML file will print an error messague and exit |
| mode | The mode we open the document. If we open the document in readonly mode we can't save the changes in the same file, so it's safe always to read from a XML without breaking it |
| ~XmlConfig ()
| ~XmlConfig |
DESTRUCTOR Nothing to be done, qt cares about freeing dom objects memory when we die
| int howManyTags (const QString tag)
| howManyTags |
Parameters:
| tag | It's the tag we look for, we return the number of the tags with this name in the domain |
| domain | It's the domain we look the tags in. If domain is NULL, we look in
the entire document. Example |
Returns: the number of tags with name tag in the domain domain
| int howManyAtributes (QString tag)
| howManyAtributes |
how many atributes has a tag, useful to navigate between the atributes
Parameters:
| tag | in the form "x[n].y[m].z[p]" |
Returns: the number of atributes of tag
| bool save (const QString file=NULL)
| save |
Saves the xml data in a file named file and flush it to disk. If the filename is null it will write the data to the same file it reads it from. Note that the constructor of this object needs to be said explicitely that you want to save data with IO_ReadWrite
Parameters:
| file | the file we want to save the XML data in |
Returns: true if success or false otherwise
| QDomDocument cloneDocument ()
| cloneDocument |
it's useful to be called from the constructor that will make a new xmlconfig object with the same data but not necesary accesed in the same way, so you can write to the file afterwards. With the same or other name The changes in this xmlconfig data will not affect the other xmlconfig data
Returns: the entire xml document
| QString file ()
| file |
return the name of the file we have taken the data from if we save the data in other file, this method will return the name of the new file In short, it returns the name of the representation of the data in disk (surely not updated)
Returns: the name of the file
| QString readString (const QString tag)
| readString |
The general form of the tag is "x[n].y[m].z[p]" We look for the string in the xml doc the string must be unique or we will just return the first one we find. The numbers are known thanks to howManyTags(); TODO?: it's trivial to implement a way to detect a non-unique string so we can return the error but it will require other param
Parameters:
| tag | from where we are going to read data |
Returns: the data from the tag with name tag
| int readInt (const QString key)
| readInt |
Returns: the integer in the string, integer is a very common type so it's worthy
| bool write (const QString tag,const QString value)
| write |
Writes the value value in the tag tag , it's done in memory if you want to modify the file .save() must be called to sync data with disk
Parameters:
| tag | the tag where we want to write the value |
| value | the value to be written |
Returns: true if succesfull , false otherwhise (false if the tag don't exist)
| bool write (const QString tag,const int value)
| write |
Same as above, writes a integer in the xml configuration
Parameters:
| tag | the tag where we want to write the value |
| value | the value to be written |
Returns: true if succesfull , false otherwhise
| bool doWrite (const QString tag, const QString value)
| doWrite |
The same that write but if the tag dont exist it will create it and write the value
Parameters:
| tag | the tag to be written |
| value | the value to be written |
Returns: true if succesfull false otherwise
| bool doWrite (const QString tag, const int value)
| doWrite |
A convenient function, lots of times, we'll write int
Parameters:
| tag | the tag to be written |
| value | the value to be written |
Returns: true if succesfull false otherwise
| bool createElement (const QString node_name, const QString value=NULL, const QString comment=NULL)
| createElement |
This will create a new Element in the xml taking the root as the
jail we are in , we have the x[].y[].z[] notation again.
This will create a
Parameters:
| node_name | the name for this element |
| value | the value, for convenience, it saves to call write afterwards |
| comment | the comment that will be written JUST BEFORE, half implemented |
Returns: true if success false if fail.
| bool deleteElement (const QString tag)
| deleteElement |
This will delete a element
Parameters:
| tag | the tag to be deleted in x.y.z notation |
Returns: true if succesful , false if not found
| bool setDomain (const QString domain, bool overwrite_domain=false)
| setDomain |
Limit the scope of all the operations to the domain in domain This make the reads/writes more efficient but are not in any way necesary so you can just ignore setDomain and releaseDomain in your application note that as you enter in a jail when using this function you must take care about exiting from it using releaseDomain you can anidate domains, setDomain(a) ; setDomain (b) will set the domain to a.b and so on note that you can say if the domain you are setting is global (relative to the document) or relative to the current domain, so : setDomain("a.b.c", true); is the same that setDomain("a"); setDomain(b); setDomain(c);
Parameters:
| domain | domain in simple x[n].y[m].z[p] notation |
| overwrite_domain | true if you set a new domain , false if the domain is relative to the old domain |
Returns: true if success , false when fails.
| bool releaseDomain (const QString domain)
| releaseDomain |
Just release the jail the setDomain() enter us in, read the setDomain comment the domain must be a simple string no need to specify [] as we take care of releasing just what was set. for instance: setDomain ("disk[1].partition[2].geometry") releaseDomain("geometry"); will let the domain set to disk[1].partition[2] releaseDomain("partition"); will let the domain set to disk[1] releaseDomain("disk"); will eliminate the jail at all
Parameters:
| domain | the domain to be released |
Returns: true if successful
| bool createComment (const QString tag, const QString comment)
| createComment |
It will create a comment just over the tag tag the comments are not parsed with this API, so you can't change nor delete them (not yet)
Parameters:
| tag | the tag over where we put the comment |
| comment | the comment we want to write |
Returns: true if succesful , false otherwise
| int readIntSimple (const QString key)
| readIntSimple |
API 2 The simple methods will access in a herarquical way. This methods are going to die, just leaving it in case the other way of doing things turns on complex code. We must not use it as it will be removed.
| QString readStringSimple (const QString tag)
| readStringSimple |
API 2 Looks for the string in the XML file and returns the value asociated to it
| long long readSectorSimple (const QString tag)
| readSectorSimple |
API 2 The same as above, it returns a sector
| bool writeSimple (const QString tag,const QString value)
| writeSimple |
API 2 Writes a value in the Xml tag with name key. In case this node "don't have space" (it just have other tags, no values) It will enter this level so the next time we try to read/write will do it here Note that this means that the XML file tags MUST EXIST even if they have void data It also means that when you enter a level you must be careful because if you look for something outside it you'll go out so you'll have to enter again. The aim is that this never happens so the code seems pretty natural, and easy to follow.
Returns: true if success or false otherwhise
| bool writeSimple (const QString tag,const int value)
| writeSimple |
API 2 Same as above, writes a integer in the xml configuration
| QDomNode nodeFromTag (const QString tag)
| nodeFromTag |
[private]
This method finds a node from a tag name. It understand the x[n].y[m].z[p] thing and will be used everywhere
Parameters:
| tag | the tag we want to find in this document |
Returns: the node in the document with this tag as name
| QDomNode find (const QString tag,const QDomNode from, bool anidate=true)
| find |
[private]
Helper function for nodeFromTag. It just return the first node found. We first look all the siblings and then begin to enter in the next level so in the end we must have walked the entire tree. It's not very efficent for now.
Parameters:
| tag | the tag name we are looking for |
| from | we start looking in this node "inwards" |
| anidate | if true we'll search between the children, if false we'll search between the siblings |
Returns: the first node with this node found
| QString discardBracket (QString token, int *number)
| discardBracket |
[private]
Yet another helper method, it accepts a string token[number] and returns token and number with no [ ].
Parameters:
| token | is the QString that we want to parse |
| number | is the number inside the brackets |
Returns: the parsed string
| QString lookForward (const QString tag)
| lookForward |
[private]
API 2 Looks in the same level from the current node to the end, if doesn't find anything just return null, else it modifies the current node and return the text found
| QString lookBackward (const QString tag)
| lookBackward |
[private]
API 2 Looks backwards in the same level from the current node to the end, if doesn't find anything just return null, else it modifies the current node and return the text found
| QDomElement nextElement (QDomNode node)
| nextElement |
[private]
| QFile * f | f |
[private]
| int mode | mode |
[private]
| QDomDocument * doc | doc |
[private]
| QDomNode currentNode | currentNode |
[private]
| QDomNode domain | domain |
[private]