开发者

What is this (0x01000000) and how do I store it?

So I've created an XML file that will configure an application that has already been built. Up until now, it was hard-coded with constants that represented offset values in flash memory.

enum {
    MAIN_FLASH_OFFSET      = 0x01000000,
    LOADER_FLASH_OFFSET    = 0x01e00000,
    MICROCODE_FLASH_OFFSET = 0x00060400,
    DRIVER_FLASH_OFFSET    = 0x00100000,
    OTHER_FLASH_OFFSET     = 0x00500000
} ModuleOffsets;

I have modified the application to read from the XML file to configure these offsets based dynamically, based on the graphics card that the user chooses.

In one of my header files, I have added the following to replace the previous enum:

    int MAIN_FLASH_OFFSET;
    int LOADER_FLASH_OFFSET;
    int MICROCODE_FLASH_OFFSET;
    int DRIVER_FLASH_OFFSET;
    int OTHER_FLASH_OFFSET;

Here's my problem. I am using TinyXML to parse the document. Below is a portion of the XML, and my code where I want to pull in these values. When it tries to pull it in, it is having trouble because GetText() returns a string, and the values (0x01000000, etc...) are ints (at least I think.

So how exactly do I store these? I real开发者_如何学编程ly have no clue, but I feel like I'm close.

XML (the actual file has multiple card entries)

<EGCs xmlns="http://tempuri.org/XMLSchema.xsd">
  <card type="EGC1">
    <offsets>
      <flashOffset>0x01000000</flashOffset>
      <loaderFlashOffset>0x01e00000</loaderFlashOffset>
      <microFlashOffset>0x00060400</microFlashOffset>
      <driverFlashOffset>0x00100000</driverFlashOffset>
      <otherFlashOffset>0x00500000</otherFlashOffset>
    </offsets>
  </card>
</EGCs>

Code

    COFPFileGeneratorDlg ofp;
    TiXmlDocument doc("EGC_Cards.xml"); 
    if(doc.LoadFile())
    {
        TiXmlHandle hDoc(&doc);
        TiXmlElement *pRoot, *pParm;
        pRoot = doc.FirstChildElement("EGCs");
        if(pRoot)
        {
            pParm = pRoot->FirstChildElement("card");
            while(pParm)
            {
                if(pParm && pParm->Attribute("type") == m_dConfigDlg.m_strEGCType)
                {
                    ofp.MAIN_FLASH_OFFSET = pRoot
                        ->FirstChildElement("card")
                        ->FirstChildElement("flashOffset")
                        ->GetText();

                        [...]
                        // close braces


Convert the string to a string stream and read the value into your integer. Using atoi(abc) would probably work also.

#include <ios>
#include <sstream>

int i;
string abc = "0x001";

stringstream convert ( abc );

convert>> std::hex >> i;

The majority of that code came from a 10 second google search.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜