简体   繁体   English

如何将 Corba 结构(包含“任何”类型)复制到 C++ 结构中

[英]How to copy a Corba struct (containing an "any" type) into a C++ struct

In Corba, I have a struct like so:在 Corba 中,我有一个像这样的结构:

module XYZ {
    typedef string AttributeName;  
    struct AttributeColumn {
        AttributeName name;              // Column attribute name
        any    data;                     // Column attribute value
    };
    typedef sequence <AttributeColumn> AttributeTable;
}

It contains values from a corresponding Sqlite database table which has the following field:它包含来自相应 Sqlite 数据库表的值,该表具有以下字段:

ABC_Name VARCHAR NOT NULL UNIQUE

I want to copy these values into a C++ struct, which consists of the following:我想将这些值复制到 C++ 结构中,该结构包含以下内容:

namespace DEF {
    typedef std::string AttributeName;
    typedef std::vector<std::string> StringCol;
    struct AttributeColumn {
        AttributeName name;              // Column attribute name
        StringCol str;                   // Column values if string
    };
   typedef std::vector<AttributeColumn> AttributeTable;
}

Here is my attempt:这是我的尝试:

XYZ::AttributeTable & xyz_table = getAttributeTable (); // This gives me the table containing the data from the database.
int rows = getLength ( xyz_table ); // This gives me the number of rows in the database.
DEF::AttributeTable def_table;

for (int i=0;i<rows;i++) {
    def_table[i].name = xyz_table[i].name;
    std::cout << def_table[i].name << std::endl;
    xyz_table[i].data >>= def_table[i].str;
    std::cout << def_table[i].str << std::endl;
}

However, the above does not compile.但是,上述内容无法编译。 I get the following error message:我收到以下错误消息:

ERROR: 1> error: no match for ‘operator>>=’ (operand types are ‘CORBA::Any’ and ‘DEF::StringCol’ {aka ‘std::vector<std::basic_string<char> >’})

If I comment out the last two lines in the for loop, then the code compiles, but it crashes.如果我注释掉 for 循环中的最后两行,则代码会编译,但会崩溃。 So, somehow, the copy into the def_table for the "name" field does not work correctly either.因此,不知何故,复制到 def_table 的“名称”字段也无法正常工作。

try this :尝试这个 :

namespace DEF {
typedef std::string AttributeName;
typedef std::vector<std::string> StringCol;
struct AttributeColumn {
    AttributeName name;              // Column attribute name
    CORBA::Any str;                   // Column values if string
};
typedef std::vector<AttributeColumn> AttributeTable;
};

because str need to be the same type of data .因为 str 需要是相同类型的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM