Extension for standard library
http_client_test.cpp
http_test.cpp
sim_test.cpp
socket_test.cpp
svg_test.cpp
t_http.hpp
t_http_tools.hpp
t_sock_wrapper.hpp
t_websocket_tools.hpp
t_blob.hpp
t_file.hpp
t_interval_map.hpp
t_json_.hpp
t_math.hpp
t_meta.hpp
t_process.hpp
t_random.hpp
t_shared.hpp
t_simulaltion.hpp
t_trie.hpp
t_url.hpp
t_visual.hpp
binary data manager
file and path management tools
template interval map implementation
CPP JSON processor
Allows you use JSON as easy as it on JavaScript
-
Overview
This filet_json.hppcontains 3 main interfaces:Classes,Static variablesandFunctoins. -
Create JavaScript variable
Using t_json, you can easily create json variables by the classvarand its aliaslet.var a = 1; // create a Number variable var b = true; // create a Boolean variable var c = "hello world"; // craete a String variable var d = undefined; // create an undefined variable
You can also use
letwhich is exactly the same asvar.
To create anArrayofObject,constructorfunctions needed to be called. Whether or not the keywordnewis used. The classvarwill automaticly clean the space after the variable's lifecircle has ended. As below:var e = Array()is the same asvar f = new Array().var e = Array(); var f = new Array(); var g = Object(); var h = new Object(); Array* arr = new Array(); var i = arr;
-
Operations
The classvarsupports basic operators of Number, Boolean and String. Using operators is just like using them in JavaScript.var arr = new Array(); for (let i = 0; i < 10; ++i) { arr.push(i); }
To access the chlidren of an
ObjectorArray, you can just use operator[]var arr = new Array(1,"2",ture); var obj = new Object({{"child_0":true},{"child_1":"hello world"}}); var arr_0 = arr[0]; //arr_0 is Number 1 var& arr_1 = arr[1]; //arr_1 is a reference to the variable at index of 1 in the arr var child_0 = obj["child_0"]; // child_0 is true var idx = "child_1"; var& child_1 = obj[idx]; // child_1 is a reference of variable at the index of child_1 in the obj obj["child_2"] = 10.5; // to emplace an item into the obj
-
Serialization and Deserialization
TheJSONglobal variable provides you the way of serialization and deserialization. You can useJSON.parseandJSON.createfor serialization.
JSON.parseforstd::string,Stringandconst char*, whileJSON.create
let you write inline JSON script in C++ code.var json_obj_1 = JSON.parse("{\"child\":1}"); var json_obj_2 = JSON.create({"child":1});
You can use
JSON.stringfyto convert a JSON object to String.std::string json_str = JSON.stringfy(json_obj_1);_
for math functions and draw points
create stop resume pause and HOOK processes
random wrapper functions
create variables in the shared memory -- shared variable on local
trie implementations
data visualization tools like SVG
You can simply use these APIs to create your simulation system
simulation module only work for c++ standards newer thanC++20
Here is the processes of run an env
// Create the Env instance
sim::Env env;
// add sth. into the env
Car* car1= env.emplace_obj<Car>();
Car* car2= env.emplace_obj<Car>();
Collision* coll = env.emplace_obj<Collision>();
// finally, run your env
env.run();You can add anything into your environment, just make sure your classes are derived from the interface of Object
You must overwrite 3 member functions -- start(), stop() and tick(size_t step).
class YourClass:public sim::Object{
public:
sim::Coro start(){}
void stop(){}
void tick(size_t step){}
};When you call the function Env::run(), the YourClass::start() will be called.
As you see, the YourClass::start() is a coroutine function. Therefore, You can use key words like co_await,co_return and co_yield.
YourClass::stop() will be called at the time that the environment is closing.
YourClass::tick() will be called on every tick of the environment.
More information please refer to the code: