tinybind编译和运行

1.背景

       XML是一种极好的语言,可以对现实实际和项目进行合理描述。XML解析也有各种成熟的方案。C++是一种常用的语言,有成熟的XML解析工程用于C++。但XML直接转C++的结构体,是一种不太好完成的事情。于是,各种搜资料,发现tinybind是一种比较好的XML与C++互相转换的工具。

2.遇到的问题

      下载tinybind有两个地址:

       1)https://github.com/tyt2y3/tinybind

       2)https://liquidtelecom.dl.sourceforge.net/project/tinybind/tinybind/0.1/tinybind.tar.gz

      但TinyBind遇到的问题是,长期没人用了,现在已经荒废了。

      我用链接源2进行下载,然后,放进QT里运行。

      编译时发现问题如下:

      1)tinybind/tinybind.h:222: error: there are no arguments to 'params' that depend on a template parameter, so a declaration of 'params' must be available [-fpermissive]

     这个需要把using IMemberHolder<T>::tag; 和 using IMemberHolder<T>::params; 放入子类,具体如下:

     

template<class T, class MT>
  class FromXmlElement : public IMemberHolder<T>
{
using IMemberHolder<T>::tag;
using IMemberHolder<T>::params;

public:
    IMemberValuePolicy<T, MT> * mvPolicy_;
    ...
};

...

template<class T, class MT>
  class FromXmlChildElement : public IMemberHolder<T>
{
using IMemberHolder<T>::tag;
using IMemberHolder<T>::params;

public:
    IMemberValuePolicy<T, MT> * mvPolicy_;
    ...
};
...
template<class T, class MT>
  class FromXmlAttribute  : public IMemberHolder<T>
{
using IMemberHolder<T>::tag;
using IMemberHolder<T>::params;

public:
    IMemberValuePolicy<T, MT> * mvPolicy_;
};

    2)error: specializing member '::GetTiXmlBinding<MyData>' requires 'template<>' syntax  TiXmlBinding<MyData> const *
解决方法:
    TiXmlBinding<MyData> const *GetTiXmlBinding<MyData>(MyData const &, Identity<MyData>)
   改为 TiXmlBinding<MyData> const *GetTiXmlBinding(MyData const &, Identity<MyData>)

3)在Linux上会有error: 'stricmp' was not declared in this scope,在Linux上,可以加一条语句:

#ifndef WIN32
#define stricmp strcasecmp
#endif

4)error: 'ConvertFromString' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
       ConvertFromString( attributeValue, &mv );
解决方法:
把void ConvertFromString(char const * strIn, T * dataOut); 放到调用者的前面.

 5)在Windows上,会出现 undefined reference to `char const* ConvertToString<char const*>(char const* const&)' 的错误,原因是程序上的这句话:

#ifdef WIN32
#undef TIXML_USE_STL
#else
#define TIXML_USE_STL
#endif

   重新定义一下TIXML_USE_STL即可。我的做法是:

#ifdef WIN32
#undef TIXML_USE_STL
#define TIXML_USE_STL
#else
#define TIXML_USE_STL
#endif

3.参考的资料

感谢原来链接:

[1]https://blog.csdn.net/ontheroad530/article/details/50386952

[2]https://blog.csdn.net/ontheroad530/article/details/50404618

4.结论

     使用之后,我发现该程序仅仅是让XML与自己完成的C++的结构体进行对应,对于使用者来说,必须提供C++结构体和XML文件。

    已经整理好的程序已经上传至github的链接:

    https://github.com/diziqian/tinyBind

猜你喜欢

转载自blog.csdn.net/wangzhezhilu001/article/details/105659574