Question

I'm trying to create a message validation program and would like to create easily modifiable rules that apply to certain message types. Due to the risk of the rules changing I've decided to define these validation rules external to the object code.

I've created a basic interface that defines a rule and am wondering what the best way to store this simple data would be. I was leaning towards XML but it seems like it might be too heavy.

Each rule would only need a very small set of data (i.e. type of rule, value, applicable mask, etc).

Does anyone know of a good resource that I could look at that would perform a similar functionality. I'd rather not dig too deep into XML on a problem that seems to barely need a subset of the functionality I see in most of the examples I bump into.

If I can find a concise example to examine I would be able to decide on whether or not to just go with a flat file.

Thanks in advance for your input!

Was it helpful?

Solution

Personally, for small, easily modifiable XML, I find TinyXML to be an excellent library. You can make each class understand it's own format, so your object hierarchy is represented directly in the XML.

However, if you don't think you need XML, you might want to go with a lighter storage like yaml. I find it is much easier to understand the underlying data, modify it and extend functionality.

(Also, boost::serialization has an XML archive, but it isn't what I'd call easily modifiable)

OTHER TIPS

The simplest is to use a flat file designed to be easy to parse using the C++ >> operator. Just simple tokens separated by whitespace.

Well, if you want your rules to be human readable, XML is the way to go, and you can interface it nicely with c++ using xerces. If you want performance and or size, you could save the data as binaries using simple structs.

Another way to implement this would be to define your rules in XML Schema and then have an XML Data Binding tool generate the corresponding C++ object model along with the XML parsing and serialization code. One such tool (that I happen to be working on) is CodeSynthesis XSD:

http://www.codesynthesis.com/products/xsd/

For a 2-minutes overview of the idea, see the "Hello World" example in the C++/Tree mapping documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top