-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
35 lines (26 loc) · 934 Bytes
/
main.cpp
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
#include <iostream>
#include <memory>
#include "simfil/simfil.h"
#include "simfil/model/model.h"
#include "simfil/model/string-pool.h"
int main()
{
// Shared string pool.
auto strings = std::make_shared<simfil::StringPool>();
// Data model pool
auto model = std::make_shared<simfil::ModelPool>(strings);
// Put object into the pool
auto obj = model->newObject();
obj->addField("name", "demo");
// Set object as root
model->addRoot(obj);
// Compilation and evaluation environment
// to register custom functions or callbacks.
auto env = simfil::Environment{strings};
// Compile query string to a simfil::Expression.
auto query = simfil::compile(env, "name", false);
// Evalualte query and get result of type simfil::Value.
auto result = simfil::eval(env, *query, *model->root(0));
for (auto&& value : result)
std::cout << value.toString() << "\n";
}