mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
[db2] Update.
This commit is contained in:
parent
a455593f66
commit
8ac4cdc8a8
3 changed files with 54 additions and 11 deletions
|
|
@ -253,6 +253,11 @@ struct db2 {
|
||||||
|
|
||||||
files(auto &&db, auto &&base) : db{db}, tab_{base}, ind_{base}, dat_{base} {}
|
files(auto &&db, auto &&base) : db{db}, tab_{base}, ind_{base}, dat_{base} {}
|
||||||
|
|
||||||
|
void alloc(auto sz) {
|
||||||
|
tab_.f.alloc_raw(sz);
|
||||||
|
ind_.f.alloc_raw(sz);
|
||||||
|
dat_.f.alloc_raw(sz);
|
||||||
|
}
|
||||||
auto get_files() const {
|
auto get_files() const {
|
||||||
return std::set<path>{tab_.fn,ind_.fn,dat_.fn};
|
return std::set<path>{tab_.fn,ind_.fn,dat_.fn};
|
||||||
}
|
}
|
||||||
|
|
@ -293,11 +298,17 @@ struct db2 {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto alloc() {
|
||||||
|
files{*this,fn}.alloc(0);
|
||||||
|
}
|
||||||
auto open() {
|
auto open() {
|
||||||
return files{*this, fn};
|
return files{*this, fn};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string utf8_to_dbstr(const std::string &s) const {
|
||||||
|
return utf8_to_dbstr((const char8_t *)s.c_str());
|
||||||
|
}
|
||||||
std::string utf8_to_dbstr(const char *s) const {
|
std::string utf8_to_dbstr(const char *s) const {
|
||||||
return utf8_to_dbstr((const char8_t *)s);
|
return utf8_to_dbstr((const char8_t *)s);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <primitives/sw/main.h>
|
#include <primitives/sw/main.h>
|
||||||
#include <primitives/sw/settings.h>
|
#include <primitives/sw/settings.h>
|
||||||
#include <primitives/sw/cl.h>
|
#include <primitives/sw/cl.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
@ -38,7 +39,7 @@ int main(int argc, char *argv[])
|
||||||
db2 db{db_fn};
|
db2 db{db_fn};
|
||||||
auto f = db.open();
|
auto f = db.open();
|
||||||
|
|
||||||
auto tbl2 = f.find_table(u8"Ãëàéäåðû");
|
/*auto tbl2 = f.find_table(u8"Ãëàéäåðû");
|
||||||
auto valuexxx = tbl2.find_value("GL_S3_PS_FINDER2");
|
auto valuexxx = tbl2.find_value("GL_S3_PS_FINDER2");
|
||||||
auto valuexxx2 = tbl2.find_value("GL_TEST_XXX");
|
auto valuexxx2 = tbl2.find_value("GL_TEST_XXX");
|
||||||
valuexxx2.set_field("NAME", "X");
|
valuexxx2.set_field("NAME", "X");
|
||||||
|
|
@ -55,18 +56,27 @@ int main(int argc, char *argv[])
|
||||||
valuexxx2.set_field("VW2", 6.3f);
|
valuexxx2.set_field("VW2", 6.3f);
|
||||||
|
|
||||||
f(u8"Ãëàéäåðû", "GL_S3_PS_FINDER2", "NAME") = "xx";
|
f(u8"Ãëàéäåðû", "GL_S3_PS_FINDER2", "NAME") = "xx";
|
||||||
f(u8"Ãëàéäåðû", "GL_S3_PS_FINDER2", "VW2") = 4.3f;
|
f(u8"Ãëàéäåðû", "GL_S3_PS_FINDER2", "VW2") = 4.3f;*/
|
||||||
|
|
||||||
auto tbl = f.tab_.data->tables();
|
auto tbl = f.tab_.data->tables();
|
||||||
auto fields = f.tab_.data->fields();
|
auto fields = f.tab_.data->fields();
|
||||||
auto values = f.ind_.data->values();
|
auto values = f.ind_.data->values();
|
||||||
|
|
||||||
std::string spaceval(4, ' ');
|
auto prepare_string = [](auto &&in) {
|
||||||
std::string spacefield(8, ' ');
|
auto s = str2utf8(in);
|
||||||
|
boost::trim(s);
|
||||||
|
return s;
|
||||||
|
};
|
||||||
|
|
||||||
|
nlohmann::json ja;
|
||||||
for (auto &&t : tbl) {
|
for (auto &&t : tbl) {
|
||||||
std::println("{}:", t.name);
|
auto &jt = ja[prepare_string(t.name)];
|
||||||
for (auto &&v : values | std::views::filter([&](auto &v){return v.table_id == t.id;})) {
|
for (auto &&v : values | std::views::filter([&](auto &v){return v.table_id == t.id;})) {
|
||||||
std::println("{}{}:", spaceval, v.name);
|
auto vn = prepare_string(v.name);
|
||||||
|
if (jt.contains(vn)) {
|
||||||
|
throw std::logic_error{"duplicate"};
|
||||||
|
}
|
||||||
|
auto &jv = jt[vn];
|
||||||
auto max = f.dat_.f.p + v.offset + v.size;
|
auto max = f.dat_.f.p + v.offset + v.size;
|
||||||
auto p = f.dat_.f.p + v.offset;
|
auto p = f.dat_.f.p + v.offset;
|
||||||
while (p < max) {
|
while (p < max) {
|
||||||
|
|
@ -80,19 +90,19 @@ int main(int argc, char *argv[])
|
||||||
case db2::field_type::integer: {
|
case db2::field_type::integer: {
|
||||||
auto fv = (int*)p;
|
auto fv = (int*)p;
|
||||||
p += vb->size;
|
p += vb->size;
|
||||||
std::println("{}{}: {}", spacefield, f->name, *fv);
|
jv[prepare_string(f->name)] = *fv;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case db2::field_type::float_: {
|
case db2::field_type::float_: {
|
||||||
auto fv = (float*)p;
|
auto fv = (float*)p;
|
||||||
p += vb->size;
|
p += vb->size;
|
||||||
std::println("{}{}: {}", spacefield, f->name, *fv);
|
jv[prepare_string(f->name)] = *fv;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case db2::field_type::string: {
|
case db2::field_type::string: {
|
||||||
auto fv = (const char*)p;
|
auto fv = (const char*)p;
|
||||||
p += vb->size;
|
p += vb->size;
|
||||||
std::println("{}{}: {}", spacefield, f->name, fv);
|
jv[prepare_string(f->name)] = prepare_string(fv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
@ -102,6 +112,28 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
write_file(path{db_fn} += ".json", ja.dump(1));
|
||||||
|
|
||||||
|
db2 x{path{db_fn} += "new"};
|
||||||
|
x.alloc();
|
||||||
|
auto newdb = x.open();
|
||||||
|
for (auto &&[t,vals] : ja.items()) {
|
||||||
|
for (auto &&[v,fields] : vals.items()) {
|
||||||
|
for (auto &&[f,val] : fields.items()) {
|
||||||
|
auto s = newdb(t, v, f);
|
||||||
|
if (0) {
|
||||||
|
} else if (val.is_number_float()) {
|
||||||
|
s = val.get<float>();
|
||||||
|
} else if (val.is_number_integer()) {
|
||||||
|
s = val.get<int>();
|
||||||
|
} else if (val.is_string()) {
|
||||||
|
s = val.get<std::string>();
|
||||||
|
} else {
|
||||||
|
throw std::logic_error{"bad type"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
sw.cpp
2
sw.cpp
|
|
@ -47,7 +47,7 @@ void build(Solution &s)
|
||||||
|
|
||||||
add_exe_with_data_manager("db_add_language") += "pub.egorpugin.primitives.executor"_dep;
|
add_exe_with_data_manager("db_add_language") += "pub.egorpugin.primitives.executor"_dep;
|
||||||
add_exe_with_data_manager("db_extractor");
|
add_exe_with_data_manager("db_extractor");
|
||||||
add_exe_with_data_manager("db_extractor2");
|
add_exe_with_data_manager("db_extractor2") += "org.sw.demo.nlohmann.json.natvis"_dep;
|
||||||
add_exe_with_data_manager("mmm_extractor");
|
add_exe_with_data_manager("mmm_extractor");
|
||||||
add_exe_with_data_manager("mmo_extractor");
|
add_exe_with_data_manager("mmo_extractor");
|
||||||
add_exe_with_common("mmo_extractor2");
|
add_exe_with_common("mmo_extractor2");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue