protean
is a library for representing hierarchical data in a uniform way across multiple platforms.
The library defines a variant
object that can hold primitive data as well as collections (e.g. lists, dictionaries) with arbitrary depth. The variant can be inspected, enumerated, and/or serialised to XML/binary format.
Protean has implementations in C++, C# and Python.
Protean is known to build on:
- Windows with MS Visual Studio 2013, 2015, 2017
- Mac with scons 3.0.1 and LLVM 9.0.0
- RHEL Linux with GCC 4.8.5
On Windows, the following method will work:
- Install Boost. (Known to work with 1.55 and 1.66.)
- Install Xerces. (Known to work with version 3.1.1.)
- Copy projects/vc1x/vc1x-paths.props.template to projects/vc1x/vc1x-paths.props. Edit the latter to set
BOOST_VERSION
,BOOST_ROOT
, andXERCES_ROOT
appropriately. - Open projects/vc1x-protean.sln in your chosen version of Visual Studio.
- Choose a configuration, e.g.
vc141 Release
andx64
, and Build Solution.
On other platforms:
- Install
boost
,xerces
andscons
dependencies, e.g. viayum
orapt-get
. - Build via
scons
. - If you wish to provide alternate include or lib paths, set
CPPPATH
orLIBPATH
env vars respectively. You can also override the Boost version, viaBOOST_VERSION
.
using variant = protean::variant;
variant root(variant::Dictionary);
variant books(variant::Dictionary);
variant book(variant::Dictionary);
variant book_attrs(variant::Dictionary);
book_attrs.insert("author", variant("XYZ"));
book_attrs.insert("year", variant(2013));
book.insert(protean::xml_attributes, book_attrs);
book.insert(protean::xml_text, variant("some text"));
books.insert("book", book);
root.insert("books", books);
std::stringstream contents;
protean::xml_writer writer(contents, xml_mode::Preserve | xml_mode::Indent);
writer << root;
std::cout << contents.str() << std::endl;
This will output:
<?xml version="1.0" encoding="utf-8"?>
<books>
<book author="XYZ" year="2013">some text</book>
</books>
We welcome contributions and feedback. Please make use of GitHub's issue tracking and pull requests.