i want to serialize a self-defined tree to a binary file and vice-versa.
The data structure is as follows:
class Node
{
public:
Node();
Node(int type,const string &name);
~Node();
string getNodeName();
int getNodeType();
Node *getNodeParent();
bool setNodeName(string &name);
bool setNodeType(int type);
bool setNodeParent(Node *parent);
.............................................................
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & type;
ar & name;
}
int type;
string name;
Node *parent;
public:
vector<Node *> children; // children list of current node
vector<AttribNode *> attribList; // attribute list of current node
};
class AttribNode
{
public:
AttribNode();
AttribNode(string attribName,int attribType,const char* value);
string getAttribName();
int getAttribType();
int attribNum = temp->attribList.size();
oa << attribNum;
for(int i =0;i < temp->attribList.size();i++)
{
oa << *(temp->attribList.at(i));
if (temp->attribList.at(i)->getAttribType() == ATTRIBUTE_TYPE_BINARY)
{
char * ptr = temp->attribList.at(i)->binValue;
long size = temp->attribList.at(i)->binSize;
oa << ptr[size];
}
}
int childrenNum = temp->children.size();
oa << childrenNum;
nodeQueue.pop();
}
return true;
}
bool ConfigRegistry::getConfigTreeFromLocal()
{
ofstream ifs("D:\\Config.bin",ios::binary);
boost::archive::binary_oarchive ia(ifs);
int childNum = 0;
int attribNum = 0;