-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo1.cc
51 lines (35 loc) · 1.22 KB
/
demo1.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// demo1: construct two objects dinamically using the add<component_t>(id) syntax
#include <string>
#include <sstream>
#include <iostream>
#include "kult.hpp"
using namespace kult;
// our obj components
using name = component<'name', std::string >;
using position = component<'posf', float >;
using description = component<'desc', std::string >;
// our sample
#include <vector>
int main( int argc, char **argv )
{
{
// construct two objects dinamically
int obj1 = 1, obj2 = 2;
add<name>(obj1) = "obj1";
add<position>(obj1) = 1.f;
add<description>(obj1) = "this is our first object";
copy( obj2, obj1 );
get<name>(obj2) = "obj2";
get<position>(obj2) ++;
del<description>( obj1 );
// check properties
std::cout << "obj1 " << ( has<description>(obj1) ? "has" : "misses" ) << " description field" << std::endl;
std::cout << "obj2 " << ( has<description>(obj2) ? "has" : "misses" ) << " description field" << std::endl;
// print objects
std::cout << dump(obj1) << std::endl;
std::cout << dump(obj2) << std::endl;
purge(obj2);
std::cout << dump(obj2) << std::endl;
}
return 0;
}