Difference between revisions of "VValue"

From Armagetron
(now it can be trapped)
 
(One intermediate revision by one other user not shown)
Line 29: Line 29:
 
=== Getting the Value ===
 
=== Getting the Value ===
  
==== GetValue ===
+
=== GetValue ===
  
 
to get the value, you use GetValue:
 
to get the value, you use GetValue:
Line 211: Line 211:
 
==== vValue::Expr::Bindings::MathExpr ====
 
==== vValue::Expr::Bindings::MathExpr ====
 
TODO
 
TODO
 +
 +
[[Category:Development]]

Latest revision as of 14:03, 24 August 2021

Intro

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

Basic Type

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...

Construction

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

GetValue

to get the value, you use GetValue:

e->GetValue()

Get<>

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<>:

e->Get<float>()

vValue Classes

values/vCore

This defines the core stuff needed for vValue.

vValue::Expr::Core

Core expression classes.

Base

This is just your basic expression. It doesn't do much useful. Its value is null.

Number<typename CType>

This template is used to define both Int and Float.

Int

Int holds a literal integer value.

Float

Float holds a literal floating point number value.

String

String holds a literal tString value.

UnaryOp

A base class for unary operators, such as Expr::Logic::Not

BinaryOp

A base class for binary operators, such as Expr::Math::Add

vValue::Type

You can omit the '::Type' if you want. These are types defined for vValue.

Set

TODO: someone who knows, describe it!

BasePtr

It's a shared pointer to an expression object. It automatically deletes when nobody wants it anymore...

Variant

This could be any literal value. Right now, this means either int, float, or tString.

arglist

This is just a deque of BasePtr arguments to pass to the registry for construction of a new expression.

vValue::Creator<>

This template is more or less an automatic factory. It turns constructors into static functions so you can pass a pointer to it.

values/vParser

vValue::Parser

This is the expression parser. It takes a tString and turns it into a tree of vValue expressions.

values/vRegistry

The registry allows expressions to be registered as functions to be called from strings the Parser takes.

vValue::Registry

Registration

This class is used to register a function:

Registration register_sin("func\nmath", "sin", 1, (Registration::fptr)
                          ( ctor::a1* )& Creator<Trig::Sin>::create<BasePtr> );
Registry

This is the class for the registry itself, instancised as theRegistry.

theRegistry

This is the registry. It is used to dynamically create expression classes that are registered with it.

ctor

These are static constructor function definitions, for a number of arguments. ctor::a0 is a ctor that has no arguments.

values/vCollection

TODO: I have no idea how this is supposed to work-- ph?

vValue::MiscWTF

FooPtrOps

TODO

myCol

TODO

vValue::Expr::Collection

BaseExt
ColNode
ColUnary
ColPickOne
ColBinary
ColUnion
ColItersection
ColDifference

values/veComparison

vValue::Expr::Comparison

GreaterThan

> operator

GreaterOrEquals

>= operator

Equals

== operator

LessOrEquals

<= operator

LessThan

< operator

Compare

<=> operator -- return -1 if <, 0 if ==, or 1 if >

if !(x<y||x==y||x>y)&&x!=y (NANs happen to act like that), then it returns NAN.

values/veLogic

vValue::Expr::Logic

Condition

a1 ?: a2 !: a3

Not

!arg

values/veMath

vValue::Expr::Math

Add =

+ operator

Subtract

- operator

Multiply
  • operator
Divide

/ operator

Random

A random integer.

vValue::Expr::Math::Trig

Sin

The radial sine of its argument.

values/vebCFunction

This file provides templates for simple C function bindings.

vValue::Expr::Bindings::CFunction

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.

values/vebLegacy

TODO

vValue::Expr::Bindings::Legacy

Callback??
ConfItem??

values/vebMathExpr

vValue::Expr::Bindings::MathExpr

TODO