这是什么(0x01000000)以及如何存储它?
因此,我创建了一个 XML 文件来配置已构建的应用程序。到目前为止,它是用表示闪存中偏移值的常量进行硬编码的。
enum {
MAIN_FLASH_OFFSET = 0x01000000,
LOADER_FLASH_OFFSET = 0x01e00000,
MICROCODE_FLASH_OFFSET = 0x00060400,
DRIVER_FLASH_OFFSET = 0x00100000,
OTHER_FLASH_OFFSET = 0x00500000
} ModuleOffsets;
我已修改应用程序以从 XML 文件中读取数据,以根据用户选择的显卡动态配置这些偏移量。
在我的一个头文件中,我添加了以下内容来替换之前的枚举:
int MAIN_FLASH_OFFSET;
int LOADER_FLASH_OFFSET;
int MICROCODE_FLASH_OFFSET;
int DRIVER_FLASH_OFFSET;
int OTHER_FLASH_OFFSET;
这是我的问题。我正在使用 TinyXML 来解析文档。下面是 XML 的一部分,以及我想要提取这些值的代码。当它试图将其拉入时,它遇到了麻烦,因为 GetText() 返回一个字符串,并且值(0x01000000 等...)是整数(至少我认为。
那么我到底如何存储这些呢?我真的不知道,但我觉得我已经很接近了。
XML(实际文件有多个card条目)
<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>
代码 >
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
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 really 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将字符串转换为字符串流并将值读入整数。使用atoi(abc)可能也可以。
该代码的大部分来自 10 秒的谷歌搜索。
Convert the string to a string stream and read the value into your integer. Using
atoi(abc)
would probably work also.The majority of that code came from a 10 second google search.