VirtualBox

Changeset 22173 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Aug 11, 2009 3:38:59 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50951
Message:

Main: the big XML settings rework. Move XML reading/writing out of interface implementation code into separate layer so it can handle individual settings versions in the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/xml.cpp

    r21428 r22173  
    497497}
    498498
     499bool Node::nameEquals(const char *pcsz) const
     500{
     501    if (m->pcszName == pcsz)
     502        return true;
     503    if (m->pcszName == NULL)
     504        return false;
     505    if (pcsz == NULL)
     506        return false;
     507    return !strcmp(m->pcszName, pcsz);
     508}
     509
     510
    499511/**
    500512 * Returns the value of a node. If this node is an attribute, returns
     
    732744/**
    733745 * Convenience method which attempts to find the attribute with the given
     746 * name and returns its value as a string.
     747 *
     748 * @param pcszMatch name of attribute to find.
     749 * @param str out: attribute value
     750 * @return TRUE if attribute was found and str was thus updated.
     751 */
     752bool ElementNode::getAttributeValue(const char *pcszMatch, iprt::MiniString &str) const
     753{
     754    const Node* pAttr;
     755    if ((pAttr = findAttribute(pcszMatch)))
     756    {
     757        str = pAttr->getValue();
     758        return true;
     759    }
     760
     761    return false;
     762}
     763
     764/**
     765 * Convenience method which attempts to find the attribute with the given
     766 * name and returns its value as a signed integer. This calls
     767 * RTStrToInt32Ex internally and will only output the integer if that
     768 * function returns no error.
     769 *
     770 * @param pcszMatch name of attribute to find.
     771 * @param i out: attribute value
     772 * @return TRUE if attribute was found and str was thus updated.
     773 */
     774bool ElementNode::getAttributeValue(const char *pcszMatch, int32_t &i) const
     775{
     776    const char *pcsz;
     777    if (    (getAttributeValue(pcszMatch, pcsz))
     778         && (VINF_SUCCESS == RTStrToInt32Ex(pcsz, NULL, 0, &i))
     779       )
     780        return true;
     781
     782    return false;
     783}
     784
     785/**
     786 * Convenience method which attempts to find the attribute with the given
     787 * name and returns its value as an unsigned integer.This calls
     788 * RTStrToUInt32Ex internally and will only output the integer if that
     789 * function returns no error.
     790 *
     791 * @param pcszMatch name of attribute to find.
     792 * @param i out: attribute value
     793 * @return TRUE if attribute was found and str was thus updated.
     794 */
     795bool ElementNode::getAttributeValue(const char *pcszMatch, uint32_t &i) const
     796{
     797    const char *pcsz;
     798    if (    (getAttributeValue(pcszMatch, pcsz))
     799         && (VINF_SUCCESS == RTStrToUInt32Ex(pcsz, NULL, 0, &i))
     800       )
     801        return true;
     802
     803    return false;
     804}
     805
     806/**
     807 * Convenience method which attempts to find the attribute with the given
    734808 * name and returns its value as a signed long integer. This calls
    735809 * RTStrToInt64Ex internally and will only output the integer if that
     
    744818    const char *pcsz;
    745819    if (    (getAttributeValue(pcszMatch, pcsz))
    746          && (VINF_SUCCESS == RTStrToInt64Ex(pcsz, NULL, 10, &i))
     820         && (VINF_SUCCESS == RTStrToInt64Ex(pcsz, NULL, 0, &i))
    747821       )
    748822        return true;
     
    765839    const char *pcsz;
    766840    if (    (getAttributeValue(pcszMatch, pcsz))
    767          && (VINF_SUCCESS == RTStrToUInt64Ex(pcsz, NULL, 10, &i))
     841         && (VINF_SUCCESS == RTStrToUInt64Ex(pcsz, NULL, 0, &i))
    768842       )
    769843        return true;
     844
     845    return false;
     846}
     847
     848/**
     849 * Convenience method which attempts to find the attribute with the given
     850 * name and returns its value as a boolean. This accepts "true", "false",
     851 * "yes", "no", "1" or "0" as valid values.
     852 *
     853 * @param pcszMatch name of attribute to find.
     854 * @param i out: attribute value
     855 * @return TRUE if attribute was found and str was thus updated.
     856 */
     857bool ElementNode::getAttributeValue(const char *pcszMatch, bool &f) const
     858{
     859    const char *pcsz;
     860    if (getAttributeValue(pcszMatch, pcsz))
     861    {
     862        if (    (!strcmp(pcsz, "true"))
     863             || (!strcmp(pcsz, "yes"))
     864             || (!strcmp(pcsz, "1"))
     865           )
     866        {
     867            f = true;
     868            return true;
     869        }
     870        if (    (!strcmp(pcsz, "false"))
     871             || (!strcmp(pcsz, "no"))
     872             || (!strcmp(pcsz, "0"))
     873           )
     874        {
     875            f = false;
     876            return true;
     877        }
     878    }
    770879
    771880    return false;
     
    870979}
    871980
     981AttributeNode* ElementNode::setAttribute(const char *pcszName, int32_t i)
     982{
     983    char *psz = NULL;
     984    RTStrAPrintf(&psz, "%RI32", i);
     985    AttributeNode *p = setAttribute(pcszName, psz);
     986    RTStrFree(psz);
     987    return p;
     988}
     989
     990AttributeNode* ElementNode::setAttribute(const char *pcszName, uint32_t i)
     991{
     992    char *psz = NULL;
     993    RTStrAPrintf(&psz, "%RU32", i);
     994    AttributeNode *p = setAttribute(pcszName, psz);
     995    RTStrFree(psz);
     996    return p;
     997}
     998
     999AttributeNode* ElementNode::setAttribute(const char *pcszName, int64_t i)
     1000{
     1001    char *psz = NULL;
     1002    RTStrAPrintf(&psz, "%RI64", i);
     1003    AttributeNode *p = setAttribute(pcszName, psz);
     1004    RTStrFree(psz);
     1005    return p;
     1006}
     1007
     1008AttributeNode* ElementNode::setAttribute(const char *pcszName, uint64_t i)
     1009{
     1010    char *psz = NULL;
     1011    RTStrAPrintf(&psz, "%RU64", i);
     1012    AttributeNode *p = setAttribute(pcszName, psz);
     1013    RTStrFree(psz);
     1014    return p;
     1015}
     1016
     1017AttributeNode* ElementNode::setAttributeHex(const char *pcszName, uint32_t i)
     1018{
     1019    char *psz = NULL;
     1020    RTStrAPrintf(&psz, "0x%RX32", i);
     1021    AttributeNode *p = setAttribute(pcszName, psz);
     1022    RTStrFree(psz);
     1023    return p;
     1024}
     1025
     1026AttributeNode* ElementNode::setAttribute(const char *pcszName, bool f)
     1027{
     1028    return setAttribute(pcszName, (f) ? "true" : "false");
     1029}
    8721030
    8731031AttributeNode::AttributeNode()
     
    9101068 * NULL, like this:
    9111069 * <code>
    912  *      xml::Node node;         // should point to an element
     1070 *      xml::ElementNode node;               // should point to an element
    9131071 *      xml::NodesLoop loop(node, "child");  // find all "child" elements under node
    914  *      const xml::Node *pChild = NULL;
     1072 *      const xml::ElementNode *pChild = NULL;
    9151073 *      while (pChild = loop.forAllNodes())
    9161074 *          ...;
     
    10181176/**
    10191177 * Returns the root element of the document, or NULL if the document is empty.
     1178 * Const variant.
    10201179 * @return
    10211180 */
    10221181const ElementNode* Document::getRootElement() const
     1182{
     1183    return m->pRootElement;
     1184}
     1185
     1186/**
     1187 * Returns the root element of the document, or NULL if the document is empty.
     1188 * Non-const variant.
     1189 * @return
     1190 */
     1191ElementNode* Document::getRootElement()
    10231192{
    10241193    return m->pRootElement;
     
    11511320 * @param doc out: document to be reset and filled with data according to file contents.
    11521321 */
    1153 void XmlFileParser::read(const char *pcszFilename,
     1322void XmlFileParser::read(const iprt::MiniString &strFilename,
    11541323                         Document &doc)
    11551324{
     
    11571326//     global.setExternalEntityLoader(ExternalEntityLoader);
    11581327
    1159     m->strXmlFilename = pcszFilename;
     1328    m->strXmlFilename = strFilename;
     1329    const char *pcszFilename = strFilename.c_str();
    11601330
    11611331    ReadContext context(pcszFilename);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette