dynamic::create_map, dynamic::create_list
This commit is contained in:
@@ -92,7 +92,7 @@ void ContentLoader::fixPackIndices() {
|
|||||||
if (fs::is_regular_file(indexFile)) {
|
if (fs::is_regular_file(indexFile)) {
|
||||||
root = files::read_json(indexFile);
|
root = files::read_json(indexFile);
|
||||||
} else {
|
} else {
|
||||||
root = std::make_shared<dynamic::Map>();
|
root = dynamic::create_map();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
|
|||||||
+12
-4
@@ -77,13 +77,13 @@ List& List::put(const Value& value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List& List::putList() {
|
List& List::putList() {
|
||||||
auto arr = std::make_shared<List>();
|
auto arr = create_list();
|
||||||
put(arr);
|
put(arr);
|
||||||
return *arr;
|
return *arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map& List::putMap() {
|
Map& List::putMap() {
|
||||||
auto map = std::make_shared<Map>();
|
auto map = create_map();
|
||||||
put(map);
|
put(map);
|
||||||
return *map;
|
return *map;
|
||||||
}
|
}
|
||||||
@@ -209,13 +209,13 @@ void Map::remove(const std::string& key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List& Map::putList(std::string key) {
|
List& Map::putList(std::string key) {
|
||||||
auto arr = std::make_shared<List>();
|
auto arr = create_list();
|
||||||
put(key, arr);
|
put(key, arr);
|
||||||
return *arr;
|
return *arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map& Map::putMap(std::string key) {
|
Map& Map::putMap(std::string key) {
|
||||||
auto obj = std::make_shared<Map>();
|
auto obj = create_map();
|
||||||
put(key, obj);
|
put(key, obj);
|
||||||
return *obj;
|
return *obj;
|
||||||
}
|
}
|
||||||
@@ -227,3 +227,11 @@ bool Map::has(const std::string& key) const {
|
|||||||
size_t Map::size() const {
|
size_t Map::size() const {
|
||||||
return values.size();
|
return values.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List_sptr dynamic::create_list(std::initializer_list<Value> values) {
|
||||||
|
return std::make_shared<List>(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map_sptr dynamic::create_map(std::initializer_list<std::pair<const std::string, Value>> entries) {
|
||||||
|
return std::make_shared<Map>(entries);
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,10 +35,16 @@ namespace dynamic {
|
|||||||
integer_t
|
integer_t
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
List_sptr create_list(std::initializer_list<Value> values={});
|
||||||
|
Map_sptr create_map(std::initializer_list<std::pair<const std::string, Value>> entries={});
|
||||||
|
|
||||||
class List {
|
class List {
|
||||||
public:
|
public:
|
||||||
std::vector<Value> values;
|
std::vector<Value> values;
|
||||||
|
|
||||||
|
List() {}
|
||||||
|
List(std::vector<Value> values) : values(std::move(values)) {}
|
||||||
|
|
||||||
std::string str(size_t index) const;
|
std::string str(size_t index) const;
|
||||||
number_t num(size_t index) const;
|
number_t num(size_t index) const;
|
||||||
integer_t integer(size_t index) const;
|
integer_t integer(size_t index) const;
|
||||||
@@ -74,6 +80,10 @@ namespace dynamic {
|
|||||||
public:
|
public:
|
||||||
std::unordered_map<std::string, Value> values;
|
std::unordered_map<std::string, Value> values;
|
||||||
|
|
||||||
|
Map() {}
|
||||||
|
Map(std::unordered_map<std::string, Value> values)
|
||||||
|
: values(std::move(values)) {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get(const std::string& key) const {
|
T get(const std::string& key) const {
|
||||||
if (!has(key)) {
|
if (!has(key)) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ gui::page_loader_func menus::create_page_loader(Engine* engine) {
|
|||||||
auto argstr = query.substr(index+1);
|
auto argstr = query.substr(index+1);
|
||||||
name = query.substr(0, index);
|
name = query.substr(0, index);
|
||||||
|
|
||||||
auto map = std::make_shared<Map>();
|
auto map = create_map();
|
||||||
auto filename = "query for "+name;
|
auto filename = "query for "+name;
|
||||||
BasicParser parser(filename, argstr);
|
BasicParser parser(filename, argstr);
|
||||||
while (parser.hasNext()) {
|
while (parser.hasNext()) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ static void show_content_missing(
|
|||||||
std::shared_ptr<ContentLUT> lut
|
std::shared_ptr<ContentLUT> lut
|
||||||
) {
|
) {
|
||||||
using namespace dynamic;
|
using namespace dynamic;
|
||||||
auto root = std::make_shared<Map>();
|
auto root = create_map();
|
||||||
auto& contentEntries = root->putList("content");
|
auto& contentEntries = root->putList("content");
|
||||||
for (auto& entry : lut->getMissingContent()) {
|
for (auto& entry : lut->getMissingContent()) {
|
||||||
std::string contentName = contenttype_name(entry.type);
|
std::string contentName = contenttype_name(entry.type);
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ dynamic::Value lua::LuaState::tovalue(int idx) {
|
|||||||
int len = lua_objlen(L, idx);
|
int len = lua_objlen(L, idx);
|
||||||
if (len) {
|
if (len) {
|
||||||
// array
|
// array
|
||||||
auto list = std::make_shared<List>();
|
auto list = create_list();
|
||||||
for (int i = 1; i <= len; i++) {
|
for (int i = 1; i <= len; i++) {
|
||||||
lua_rawgeti(L, idx, i);
|
lua_rawgeti(L, idx, i);
|
||||||
list->put(tovalue(-1));
|
list->put(tovalue(-1));
|
||||||
@@ -336,7 +336,7 @@ dynamic::Value lua::LuaState::tovalue(int idx) {
|
|||||||
return list;
|
return list;
|
||||||
} else {
|
} else {
|
||||||
// table
|
// table
|
||||||
auto map = std::make_shared<Map>();
|
auto map = create_map();
|
||||||
lua_pushvalue(L, idx);
|
lua_pushvalue(L, idx);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
while (lua_next(L, -2)) {
|
while (lua_next(L, -2)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user