RIP tp::Strings

This commit is contained in:
IlyaShurupov 2024-03-22 14:44:26 +03:00 committed by Ilya Shurupov
parent fa2d0aaa92
commit 1756ca026d
90 changed files with 419 additions and 1475 deletions

View file

@ -5,7 +5,6 @@
#include "Map.hpp"
#include "List.hpp"
#include "Buffer.hpp"
#include "Strings.hpp"
#include "LocalConnection.hpp"
#include "core/typegroups.h"
@ -14,6 +13,8 @@
#include "Archiver.hpp"
#include "SizeCounter.hpp"
#include <string>
//#include "interpreter/interpreter.h"
/* Steps to create custom Object:
@ -38,6 +39,7 @@ implement construct, destruct and copy methods */
namespace obj {
template<bool tRead>
class Archiver : public tp::ArchiverTemplate<tRead> {
tp::LocalConnection mConnection;
@ -84,6 +86,10 @@ namespace obj {
using ArchiverIn = Archiver<true>;
using ArchiverOut = Archiver<false>;
void save_string(ArchiverOut& file, const std::string& string);
tp::ualni save_string_size(const std::string& string);
void load_string(ArchiverIn& file, std::string& out);
extern tp::ModuleManifest gModuleObjects;
extern struct objects_api* NDO;
@ -101,8 +107,8 @@ namespace obj {
typedef void (*object_from_int)(Object* self, tp::alni in);
typedef void (*object_from_float)(Object* self, tp::alnf in);
typedef void (*object_from_string)(Object* self, tp::String in);
typedef tp::String(*object_to_string)(Object* self);
typedef void (*object_from_string)(Object* self, const std::string& in);
typedef std::string(*object_to_string)(Object* self);
typedef tp::alni(*object_to_int)(Object* self);
typedef tp::alnf(*object_to_float)(Object* self);
@ -142,23 +148,23 @@ namespace obj {
typedef tp::alni (*object_allocated_size_recursive)(Object*); // default value = object_allocated_size
struct ObjectType {
const ObjectType* base = NULL;
object_constructor constructor = NULL;
object_destructor destructor = NULL;
object_copy copy = NULL;
const ObjectType* base = nullptr;
object_constructor constructor = nullptr;
object_destructor destructor = nullptr;
object_copy copy = nullptr;
tp::alni size = 0;
const char* name;
const ObjectTypeConversions* convesions = NULL;
const ObjectTypeAriphmetics* ariphmetics = NULL;
object_save_size save_size = NULL;
object_save save = NULL;
object_load load = NULL;
object_compare comparison = NULL;
void* vtable = NULL;
const char* description = NULL;
object_debug_all_childs_retrival childs_retrival = NULL;
object_allocated_size allocated_size = NULL;
object_allocated_size_recursive allocated_size_recursive = NULL;
const ObjectTypeConversions* convesions = nullptr;
const ObjectTypeAriphmetics* ariphmetics = nullptr;
object_save_size save_size = nullptr;
object_save save = nullptr;
object_load load = nullptr;
object_compare comparison = nullptr;
void* vtable = nullptr;
const char* description = nullptr;
object_debug_all_childs_retrival childs_retrival = nullptr;
object_allocated_size allocated_size = nullptr;
object_allocated_size_recursive allocated_size_recursive = nullptr;
TypeMethods type_methods;
};
@ -182,26 +188,26 @@ namespace obj {
struct objects_api {
tp::Map<tp::String, const ObjectType*> types;
tp::Map<std::string, const ObjectType*> types;
obj::TypeGroups type_groups;
Interpreter* interp = NULL;
Interpreter* interp = nullptr;
objects_api();
~objects_api();
void define(ObjectType* type);
Object* create(const tp::String& name);
Object* create(const std::string& name);
Object* copy(Object* self, const Object* in);
bool compare(Object* first, Object* second);
Object* instatiate(Object*);
void set(Object* self, tp::alni val);
void set(Object* self, tp::alnf val);
void set(Object* self, tp::String val);
void set(Object* self, const std::string& val);
tp::alni toInt(Object* self);
tp::alnf toFloat(Object* self);
bool toBool(Object* self);
tp::String toString(Object* self);
std::string toString(Object* self);
void clear_object_flags();
@ -225,8 +231,8 @@ namespace obj {
tp::alni objsize_ram_recursive_util(Object* self, const ObjectType* type, bool different_object = true);
tp::alni objsize_ram_recursive(Object* self);
bool save(Object*, tp::String path, bool compressed = true);
Object* load(tp::String path);
bool save(Object*, const std::string& path, bool compressed = true);
Object* load(const std::string& path);
tp::alni save(ArchiverOut&, Object*);
Object* load(ArchiverIn&, tp::alni file_adress);
};

View file

@ -2,7 +2,7 @@
#pragma once
#include "Map.hpp"
#include "Strings.hpp"
#include <string>
namespace obj {
@ -13,13 +13,13 @@ namespace obj {
public:
typedef tp::Map<tp::String, obj::TypeGroups*> Dict;
typedef tp::Map<std::string, obj::TypeGroups*> Dict;
TypeGroups();
friend struct obj::objects_api;
TypeGroups(bool is_group);
explicit TypeGroups(bool is_group);
void addType(ObjectType* type, tp::InitialierList<const char*> path, tp::alni cur_arg = 0);
void setType(ObjectType* type);

View file

@ -2,7 +2,7 @@
#pragma once
#include "Buffer.hpp"
#include "Strings.hpp"
#include <string>
namespace obj {
@ -13,19 +13,19 @@ namespace obj {
struct TypeMethod {
enum { MAX_ARGS = 8 };
struct Arg {
const char* descr = NULL;
mutable Object* obj = NULL;
const char* descr = nullptr;
mutable Object* obj = nullptr;
};
const char* nameid = NULL;
const char* descr = NULL;
const char* nameid = nullptr;
const char* descr = nullptr;
mutable Object* self = NULL;
mutable Object* self = nullptr;
Arg args[MAX_ARGS];
tp::int1 mNargs = 0;
void (*exec)(const TypeMethod* tm) = NULL;
void (*exec)(const TypeMethod* tm) = nullptr;
mutable Arg ret;
@ -48,7 +48,7 @@ namespace obj {
operator bool() { return key != -1; }
};
static LookupKey presents(const ObjectType*, tp::String);
static LookupKey presents(const ObjectType*, const std::string&);
static const TypeMethod* getMethod(const ObjectType*, LookupKey);
void init();
@ -56,7 +56,7 @@ namespace obj {
tp::halni nMethods() const;
private:
tp::int2 presents(tp::String) const;
tp::int2 presents(const std::string&) const;
const TypeMethod* getMethod(tp::int2) const;
};