tags:

views:

196

answers:

4

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!

+1  A: 

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)

Todd Gardner
TinyXML, didn't know about this one, I'll have to check that out
Gab Royer
TinyXML appears to have a good set of examples similar to what I'd like to do. I will be checking this out tomorrow to see if I can't throw together a quick proof of concept.Thanks for the speedy response!
Brian
+1  A: 

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

KayEss
It certainly is the simplest and will be my fallback plan if I can't get a POC up and running quickly.Thanks for your opinion!
Brian
+1  A: 

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.

Gab Royer
Yes I definitely want it human readable and a bit more self documenting than a standard value-pair or white space delimited file -- if it wasn't going to be too much overhead. It appears as though I will be able to pull together at least enough to gauge the level of effort to implement this in XML.I'll take a look at xerces as well.Thanks!
Brian
A: 

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.