Runtime » History » Version 2

J. Moringen, 02/14/2011 12:31 AM
updated according to coding style changes

1 1 J. Moringen
h1. Runtime
2 1 J. Moringen
3 1 J. Moringen
The @rsc::runtime@ namespace contains some utility classes and functions that augment the C++ runtime towards interactive and less strict handling of data and types.
4 1 J. Moringen
5 1 J. Moringen
h2. Properties
6 1 J. Moringen
7 1 J. Moringen
The @Properties@ class is basically a glorified @std::map<std::string, boost::any>@. It therefore allows associating all kinds of objects to string keys. In addition, @Properties@ supports printing to streams, merging property maps and some slightly more convenient handling of types. Example:
8 1 J. Moringen
<pre>
9 1 J. Moringen
rsc::runtime::Properties props;
10 1 J. Moringen
std::cout << "empty       " << props << std::endl;
11 1 J. Moringen
12 1 J. Moringen
props["key1"] = 1;
13 1 J. Moringen
props["key2"] = 2u;
14 1 J. Moringen
props["key3"] = 3.0;
15 1 J. Moringen
props["key4"] = std::string("four");
16 1 J. Moringen
std::cout << "some values " << props << std::endl;
17 1 J. Moringen
</pre>
18 1 J. Moringen
prints
19 1 J. Moringen
<pre>
20 1 J. Moringen
empty       p{  }
21 1 J. Moringen
some values p{ key1: 1, key2: <unsigned int>, key3: 3, key4: "four" }
22 1 J. Moringen
</pre>
23 1 J. Moringen
24 1 J. Moringen
h2. Container IO
25 1 J. Moringen
26 1 J. Moringen
The basic idea is to provide the missing @operator<<@ for STL containers. Example:
27 1 J. Moringen
<pre>
28 1 J. Moringen
std::map<std::string, double> map;
29 1 J. Moringen
map.insert(std::make_pair("a", 1.0));
30 1 J. Moringen
map.insert(std::make_pair("b", 2.0));
31 1 J. Moringen
map.insert(std::make_pair("c", 3.0));
32 1 J. Moringen
std::cout << map << std::endl;
33 1 J. Moringen
</pre>
34 1 J. Moringen
prints
35 1 J. Moringen
<pre>
36 1 J. Moringen
{a: 1, b: 2, c: 3}
37 1 J. Moringen
</pre>
38 1 J. Moringen
39 1 J. Moringen
h2. Type Strings
40 1 J. Moringen
41 1 J. Moringen
A thin wrapper for portably obtaining readable names of C++ types. Example:
42 1 J. Moringen
<pre>
43 1 J. Moringen
MyBase* base = new MyDerived();
44 2 J. Moringen
std::cout << rsc::runtime::typeName(*base) << std::endl;
45 1 J. Moringen
</pre>
46 1 J. Moringen
prints
47 1 J. Moringen
<pre>
48 1 J. Moringen
MyDerived
49 1 J. Moringen
</pre>