|
| 1 | + |
| 2 | +#include <cmath> |
| 3 | +#include <memory> |
| 4 | + |
| 5 | +#include <chaiscript/chaiscript.hpp> |
| 6 | +#include <string_id/string_id.hpp> |
| 7 | +#include <string_id/database.hpp> |
| 8 | +#include <string_id/basic_database.hpp> |
| 9 | + |
| 10 | +namespace chaiscript { |
| 11 | + namespace extras { |
| 12 | + namespace string_id { |
| 13 | + |
| 14 | + ModulePtr bootstrap(ModulePtr m = std::make_shared<Module>()) |
| 15 | + { |
| 16 | + |
| 17 | + using namespace foonathan; |
| 18 | + |
| 19 | + // default_database |
| 20 | + m->add(user_type<foonathan::string_id::default_database>(), "default_database"); |
| 21 | + m->add(constructor<foonathan::string_id::default_database ()>(), "default_database"); |
| 22 | + |
| 23 | + // basic_database |
| 24 | + m->add(user_type<foonathan::string_id::basic_database>(), "basic_database"); |
| 25 | + m->add(base_class<foonathan::string_id::basic_database, foonathan::string_id::default_database>()); |
| 26 | + |
| 27 | + // string_id |
| 28 | + m->add(user_type<foonathan::string_id::string_id>(), "string_id"); |
| 29 | + m->add(constructor<foonathan::string_id::string_id (const foonathan::string_id::string_id &)>(), "string_id"); |
| 30 | + m->add(constructor<foonathan::string_id::string_id (const foonathan::string_id::string_info &, foonathan::string_id::basic_database &)>(), "string_id"); |
| 31 | + m->add(constructor<foonathan::string_id::string_id (const foonathan::string_id::string_id &, foonathan::string_id::string_info)>(), "string_id"); |
| 32 | + m->add(fun(&foonathan::string_id::string_id::hash_code), "hash_code"); |
| 33 | + m->add(fun(&foonathan::string_id::string_id::database), "database"); |
| 34 | + m->add(fun<bool (const foonathan::string_id::string_id &, const foonathan::string_id::string_id &)>([](const foonathan::string_id::string_id &t_lhs, const foonathan::string_id::string_id &t_rhs){ return t_lhs == t_rhs; }), "=="); |
| 35 | + m->add(fun<bool (foonathan::string_id::hash_type, const foonathan::string_id::string_id &)>([](foonathan::string_id::hash_type t_lhs, const foonathan::string_id::string_id &t_rhs){ return t_lhs == t_rhs; }), "=="); |
| 36 | + m->add(fun<bool (const foonathan::string_id::string_id &, foonathan::string_id::hash_type)>([](const foonathan::string_id::string_id &t_lhs, foonathan::string_id::hash_type t_rhs){ return t_lhs == t_rhs; }), "=="); |
| 37 | + m->add(fun<bool (const foonathan::string_id::string_id &, const foonathan::string_id::string_id &)>([](const foonathan::string_id::string_id &t_lhs, const foonathan::string_id::string_id &t_rhs){ return t_lhs != t_rhs; }), "!="); |
| 38 | + m->add(fun<bool (foonathan::string_id::hash_type, const foonathan::string_id::string_id &)>([](foonathan::string_id::hash_type t_lhs, const foonathan::string_id::string_id &t_rhs){ return t_lhs != t_rhs; }), "!="); |
| 39 | + m->add(fun<bool (const foonathan::string_id::string_id &, foonathan::string_id::hash_type)>([](const foonathan::string_id::string_id &t_lhs, foonathan::string_id::hash_type t_rhs){ return t_lhs != t_rhs; }), "!="); |
| 40 | + |
| 41 | + // string_info |
| 42 | + m->add(user_type<foonathan::string_id::string_info>(), "string_info"); |
| 43 | + m->add(fun(&foonathan::string_id::string_info::string), "string"); |
| 44 | + m->add(fun(&foonathan::string_id::string_info::length), "length"); |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + // type conversions |
| 49 | + m->add(type_conversion<const std::string &, foonathan::string_id::string_info>( |
| 50 | + [](const std::string &t_str) { |
| 51 | + return foonathan::string_id::string_info(t_str.c_str(), t_str.size()); |
| 52 | + } |
| 53 | + )); |
| 54 | + |
| 55 | + // free functions |
| 56 | + m->add(fun(&foonathan::string_id::detail::sid_hash), "sid_hash"); |
| 57 | + |
| 58 | + return m; |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
0 commit comments