RIP tp::Strings
This commit is contained in:
parent
aa53a4addb
commit
893a07e924
90 changed files with 419 additions and 1475 deletions
|
|
@ -76,8 +76,6 @@ static void deinit(const tp::ModuleManifest*) {
|
|||
}
|
||||
|
||||
static tp::ModuleManifest* sModuleDependencies[] = {
|
||||
// &tp::gModuleCompressor,
|
||||
&tp::gModuleStrings,
|
||||
nullptr
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,29 @@
|
|||
|
||||
namespace obj {
|
||||
|
||||
void save_string(ArchiverOut& file, const std::string& string) {
|
||||
file << string.size();
|
||||
file.writeBytes(string.c_str(), string.size());
|
||||
}
|
||||
|
||||
tp::ualni save_string_size(const std::string& string) {
|
||||
return string.size() + sizeof(string.size());
|
||||
}
|
||||
|
||||
void load_string(ArchiverIn& file, std::string& out) {
|
||||
typeof(out.size()) size;
|
||||
file >> size;
|
||||
auto buff = new char[size + 1];
|
||||
file.readBytes(buff, size);
|
||||
buff[size] = 0;
|
||||
out = buff;
|
||||
delete[] buff;
|
||||
}
|
||||
|
||||
Object* ObjectMemAllocate(const ObjectType* type);
|
||||
void ObjectMemDeallocate(Object* in);
|
||||
|
||||
objects_api* NDO = NULL;
|
||||
objects_api* NDO = nullptr;
|
||||
|
||||
void hierarchy_copy(Object* self, const Object* in, const ObjectType* type);
|
||||
void hierarchy_construct(Object* self, const ObjectType* type);
|
||||
|
|
@ -36,7 +55,7 @@ namespace obj {
|
|||
type->type_methods.init();
|
||||
}
|
||||
|
||||
Object* objects_api::create(const tp::String& name) {
|
||||
Object* objects_api::create(const std::string& name) {
|
||||
MODULE_SANITY_CHECK(gModuleObjects);
|
||||
|
||||
const ObjectType* type = types.get(name);
|
||||
|
|
@ -44,7 +63,7 @@ namespace obj {
|
|||
Object* obj_instance = ObjectMemAllocate(type);
|
||||
|
||||
if (!obj_instance) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hierarchy_construct(obj_instance, obj_instance->type);
|
||||
|
|
@ -69,7 +88,7 @@ namespace obj {
|
|||
|
||||
Object* objects_api::copy(Object* self, const Object* in) {
|
||||
if (self->type != in->type) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hierarchy_copy(self, in, self->type);
|
||||
|
|
@ -110,7 +129,7 @@ namespace obj {
|
|||
}
|
||||
}
|
||||
|
||||
void objects_api::set(Object* self, tp::String val) {
|
||||
void objects_api::set(Object* self, const std::string& val) {
|
||||
if (self->type->convesions && self->type->convesions->from_string) {
|
||||
self->type->convesions->from_string(self, val);
|
||||
return;
|
||||
|
|
@ -134,7 +153,7 @@ namespace obj {
|
|||
return true;
|
||||
}
|
||||
|
||||
tp::String objects_api::toString(Object* self) {
|
||||
std::string objects_api::toString(Object* self) {
|
||||
DEBUG_ASSERT(self->type->convesions && self->type->convesions->to_string);
|
||||
return self->type->convesions->to_string(self);
|
||||
}
|
||||
|
|
@ -217,6 +236,6 @@ namespace obj {
|
|||
}
|
||||
typeiter = typeiter->base;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ namespace obj {
|
|||
|
||||
ObjectsFileHeader(bool default_val = true) {
|
||||
if (default_val) {
|
||||
tp::memCopy(&name, "objects", tp::String::Logic::calcLength("objects") + 1);
|
||||
tp::memCopy(&version, "0", tp::String::Logic::calcLength("0") + 1);
|
||||
tp::memCopy(&name, "objects", 8);
|
||||
tp::memCopy(&version, "0", 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -26,10 +26,10 @@ namespace obj {
|
|||
Object* ObjectMemAllocate(const ObjectType* type) {
|
||||
ObjectMemHead* memh = (ObjectMemHead*) malloc(type->size + sizeof(ObjectMemHead));
|
||||
if (!memh) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
memh->down = NULL;
|
||||
memh->down = nullptr;
|
||||
memh->flags = 0;
|
||||
|
||||
memh->refc = (tp::alni) 1;
|
||||
|
|
@ -235,10 +235,11 @@ namespace obj {
|
|||
// save file object header
|
||||
ObjectFileHead ofh = { 0, getrefc(in) };
|
||||
ndf << ofh;
|
||||
ndf << tp::String(in->type->name);
|
||||
|
||||
save_string(ndf, in->type->name);
|
||||
|
||||
// allocate for object file header
|
||||
ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + tp::SaveSizeCounter::calc(tp::String(in->type->name)));
|
||||
ndf.setFreeAddress(ndf.getFreeAddress() + sizeof(ObjectFileHead) + save_string_size(in->type->name));
|
||||
|
||||
// calc max size needed for saving all hierarchy of types
|
||||
tp::alni file_alloc_size = objsize_file_util(in, in->type);
|
||||
|
|
@ -281,14 +282,14 @@ namespace obj {
|
|||
ObjectFileHead ofh;
|
||||
ndf >> ofh;
|
||||
|
||||
tp::String type_name;
|
||||
ndf >> type_name;
|
||||
std::string type_name;
|
||||
load_string(ndf, type_name);
|
||||
|
||||
const ObjectType* object_type = NDO->types.get(type_name);
|
||||
Object* out = ObjectMemAllocate(object_type);
|
||||
|
||||
if (!out) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
setrefc(out, 0);
|
||||
|
|
@ -312,8 +313,8 @@ namespace obj {
|
|||
return out;
|
||||
}
|
||||
|
||||
bool objects_api::save(Object* in, tp::String path, bool compressed) {
|
||||
ArchiverOut ndf(path.read());
|
||||
bool objects_api::save(Object* in, const std::string& path, bool compressed) {
|
||||
ArchiverOut ndf(path.c_str());
|
||||
|
||||
if (!ndf.isOpened()) {
|
||||
return false;
|
||||
|
|
@ -365,22 +366,22 @@ namespace obj {
|
|||
return true;
|
||||
}
|
||||
|
||||
Object* objects_api::load(tp::String path) {
|
||||
Object* objects_api::load(const std::string& path) {
|
||||
/*
|
||||
auto temp_file_name = path + ".unz";
|
||||
bool unz_res = tp::decompressF2F(path.cstr(), temp_file_name.cstr());
|
||||
|
||||
if (!unz_res) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
File ndf(temp_file_name.cstr(), tp::osfile_openflags::LOAD);
|
||||
*/
|
||||
|
||||
ArchiverIn ndf(path.read());
|
||||
ArchiverIn ndf(path.c_str());
|
||||
|
||||
if (!ndf.isOpened()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// check for compatibility
|
||||
|
|
@ -390,7 +391,7 @@ namespace obj {
|
|||
ndf >> loaded_header;
|
||||
|
||||
if (!tp::memEqual(¤t_header, &loaded_header, sizeof(ObjectsFileHeader))) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ndf.setAddress(0);
|
||||
|
|
@ -423,7 +424,7 @@ namespace obj {
|
|||
/*
|
||||
ndf.close();
|
||||
|
||||
if (unz_res == NULL) {
|
||||
if (unz_res == nullptr) {
|
||||
File::remove(temp_file_name.cstr());
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using namespace obj;
|
||||
|
||||
ScriptSection* gScriptSection = NULL;
|
||||
ScriptSection* gScriptSection = nullptr;
|
||||
|
||||
struct script_data_head {
|
||||
tp::alni refc = 0;
|
||||
|
|
@ -19,7 +19,7 @@ Script* ScriptSection::createScript() {
|
|||
auto out = (Script*) (sdhead + 1);
|
||||
|
||||
if (!sdhead) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sdhead->refc = 1;
|
||||
|
|
@ -215,7 +215,7 @@ Script* ScriptSection::get_scritp_from_file_adress(tp::alni file_adress) {
|
|||
return iter.data();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ScriptSection::~ScriptSection() {
|
||||
|
|
@ -229,8 +229,8 @@ obj::save_load_callbacks ScriptSection::slcb_script_section = {
|
|||
.pre_save = (obj::pre_save_callback*) ScriptSection::save_script_table_to_file,
|
||||
.size = (obj::slcb_size_callback*) ScriptSection::save_script_table_to_file_size,
|
||||
.pre_load = (obj::pre_load_callback*) ScriptSection::load_script_table_from_file,
|
||||
.post_save = NULL,
|
||||
.post_load = NULL,
|
||||
.post_save = nullptr,
|
||||
.post_load = nullptr,
|
||||
};
|
||||
|
||||
void ScriptSection::initialize() {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ obj::TypeGroups::TypeGroups(bool is_group) :
|
|||
if (is_group) {
|
||||
new (&childs) Dict();
|
||||
} else {
|
||||
type = NULL;
|
||||
type = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ void obj::TypeGroups::addType(ObjectType* type, tp::InitialierList<const char*>
|
|||
return;
|
||||
}
|
||||
|
||||
TypeGroups* group = NULL;
|
||||
TypeGroups* group = nullptr;
|
||||
tp::alni index = 0;
|
||||
|
||||
for (auto dir : path) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
|||
.nameid = "type",
|
||||
.descr = "retrieves typeobject",
|
||||
.exec = [](const TypeMethod* tm) { tm->ret.obj = TypeObject::create(tm->self->type); },
|
||||
.ret = { "typeobject", NULL },
|
||||
.ret = { "typeobject", nullptr },
|
||||
},
|
||||
{
|
||||
.nameid = "to_str",
|
||||
|
|
@ -25,7 +25,7 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
|||
tm->ret.obj = StringObject::create(NDO->toString(tm->self));
|
||||
}
|
||||
},
|
||||
.ret = { "string object", NULL },
|
||||
.ret = { "string object", nullptr },
|
||||
},
|
||||
{
|
||||
.nameid = "to_float",
|
||||
|
|
@ -36,11 +36,11 @@ TypeMethod obj::gDefaultTypeMethods[] = {
|
|||
tm->ret.obj = FloatObject::create(NDO->toFloat(tm->self));
|
||||
}
|
||||
},
|
||||
.ret = { "string object", NULL },
|
||||
.ret = { "string object", nullptr },
|
||||
},
|
||||
};
|
||||
|
||||
tp::int2 TypeMethods::presents(tp::String id) const {
|
||||
tp::int2 TypeMethods::presents(const std::string& id) const {
|
||||
for (tp::int2 idx = 0; idx < mNMethods; idx++) {
|
||||
if (id == methods[idx]->nameid) {
|
||||
return idx;
|
||||
|
|
@ -58,7 +58,7 @@ tp::int2 TypeMethods::presents(tp::String id) const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, tp::String id) {
|
||||
TypeMethods::LookupKey TypeMethods::presents(const ObjectType* type, const std::string& id) {
|
||||
|
||||
tp::int2 depth = 0;
|
||||
tp::int2 idx = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue