vValue holds stuff that gives a value. It should be used for any and all configuration things. Especially when DCT is usable. Lucifer envisioned a class that could return any arbitrary data type to a hud widget. wrtlprnft implemented it as gHudValue and cleaning it up conceptually. ph added some collection stuff when he needed a class to solve a very similar problem. Luke modularized it and made an expression parser. Nobody really knows how it all works.
How To Use It
You'll want either vValue::Expr::Core::Base* or vValue::Type::BasePtr depending on what your use is, what day of the week you're born on, etc...
you make the vValue either C++ style:
e = new classname(arguments);
... by parsing a string:
e = vValue::Parser::parse("3 + 2 / 8");
... or by asking the vValue registry to do it for you:
std::vector<tString> flags; arglist args; flags.push_back("func"); args.push_back(vValue::Expr::Core::Int(7)); e = vValue::Registry::theRegistry.create(flags, "classname", args);
Getting the Value
to get the value, you use GetValue:
GetValue returns a Variant, which could be a string, float, integer, you name it! Since you usually have a particular type in mind that you need, it's better to use Get<>:
This defines the core stuff needed for vValue.
Core expression classes.
This is just your basic expression. It doesn't do much useful. Its value is null.
This template is used to define both Int and Float.
Int holds a literal integer value.
Float holds a literal floating point number value.
String holds a literal tString value.
A base class for unary operators, such as Expr::Logic::Not
A base class for binary operators, such as Expr::Math::Add
You can omit the '::Type' if you want. These are types defined for vValue.
TODO: someone who knows, describe it!
It's a shared pointer to an expression object. It automatically deletes when nobody wants it anymore...
This could be any literal value. Right now, this means either int, float, or tString.
This is just a deque of BasePtr arguments to pass to the registry for construction of a new expression.
This template is more or less an automatic factory. It turns constructors into static functions so you can pass a pointer to it.
This is the expression parser. It takes a tString and turns it into a tree of vValue expressions.
The registry allows expressions to be registered as functions to be called from strings the Parser takes.
This class is used to register a function:
Registration register_sin("func\nmath", "sin", 1, (Registration::fptr) ( ctor::a1* )& Creator<Trig::Sin>::create<BasePtr> );
This is the class for the registry itself, instancised as theRegistry.
This is the registry. It is used to dynamically create expression classes that are registered with it.
These are static constructor function definitions, for a number of arguments. ctor::a0 is a ctor that has no arguments.
TODO: I have no idea how this is supposed to work-- ph?
<=> operator -- return -1 if <, 0 if ==, or 1 if >
!(x<y||x==y||x>y)&&x!=y (NANs happen to act like that), then it returns NAN.
a1 ?: a2 !: a3
A random integer.
The radial sine of its argument.
This file provides templates for simple C function bindings.
CfZeroary<typename ReturnType, FunctionPtr>
This template wraps a C function with no arguments.
CfUnary<typename ReturnType, FunctionPtr, typename ArgType>
This template wraps a C function with one argument.
CfBinary<typename ReturnType, FunctionPtr, typename Arg1Type, typename Arg2Type>
This template wraps a C function with two arguments.