Skip to content

Commit bc1f7de

Browse files
committed
update
1 parent 9f8f294 commit bc1f7de

6 files changed

Lines changed: 21 additions & 25 deletions

File tree

CoreLib.Serialization/JsonSerializer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ namespace JxCoreLib::Serialization
4040
return enum_js;
4141
}
4242

43-
if (obj->GetType()->is_custom_primitive_type())
43+
if (IStringify* stringify = interface_cast<IStringify>(obj))
4444
{
45-
return json(obj->ToString());
45+
return json(stringify->IStringify_Stringify());
4646
}
4747

4848
//list
@@ -206,15 +206,16 @@ namespace JxCoreLib::Serialization
206206
return _DeserializeEnum(js, type);
207207
}
208208

209-
if (type->is_custom_primitive_type())
209+
if (type->IsImplementedInterface(cltypeof<IStringify>()))
210210
{
211211
if (!js.is_string()) return nullptr;
212212
sptr<Object> obj = default_v;
213213
if (default_v == nullptr)
214214
{
215215
obj = type->CreateSharedInstance({});
216216
}
217-
sptr_cast<CustomPrimitiveObject>(obj)->Parse(js.get<string>());
217+
218+
interface_cast<IStringify>(obj.get())->IStringify_Parse(js.get<string>());
218219
return obj;
219220
}
220221

CoreLib/BasicTypes.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ namespace JxCoreLib
1111

1212
};
1313

14-
class CustomPrimitiveObject : public BoxingObject
14+
class IStringify : public IInterface
1515
{
16-
CORELIB_DEF_TYPE(AssemblyObject_JxCoreLib, JxCoreLib::CustomPrimitiveObject, BoxingObject);
16+
CORELIB_DEF_INTERFACE(AssemblyObject_JxCoreLib, JxCoreLib::IStringify, IInterface);
1717

18-
public:
19-
virtual void Parse(const string& value) = 0;
20-
//override Parse and ToString
18+
virtual void IStringify_Parse(const string& value) = 0;
19+
virtual string IStringify_Stringify() = 0;
2120
};
2221

2322
class PrimitiveObject : public BoxingObject

CoreLib/Guid.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ namespace JxCoreLib
2525
static guid_t empty() { return guid_t(); }
2626
};
2727

28-
class Guid : public CustomPrimitiveObject
28+
class Guid : public BoxingObject, public IStringify
2929
{
30-
CORELIB_DEF_TYPE(AssemblyObject_JxCoreLib, JxCoreLib::Guid, CustomPrimitiveObject);
30+
CORELIB_DEF_TYPE(AssemblyObject_JxCoreLib, JxCoreLib::Guid, BoxingObject);
31+
CORELIB_IMPL_INTERFACES(IStringify);
3132
public:
3233
using unboxing_type = guid_t;
3334
guid_t get_unboxing_value() const { return this->value_; }
3435

3536
Guid() {}
3637
Guid(guid_t guid) : value_(guid) {}
3738
virtual string ToString() const override { return this->value_.to_string(); }
38-
virtual void Parse(const string& value) override { this->value_ = guid_t::parse(value); };
39-
private:
39+
public: /*Interfaces*/
40+
virtual void IStringify_Parse(const string& value) override { this->value_ = guid_t::parse(value); }
41+
virtual string IStringify_Stringify() override { return this->ToString(); }
42+
private: /*Fields*/
4043
guid_t value_;
4144
};
4245
CORELIB_DECL_SHORTSPTR(Guid);

CoreLib/Type.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ namespace JxCoreLib
9898
return this->IsSubclassOf(cltypeof<BoxingObject>());
9999
}
100100

101-
bool Type::is_custom_primitive_type() const
102-
{
103-
return this->IsSubclassOf(cltypeof<CustomPrimitiveObject>());
104-
}
105-
106-
107101
void Type::get_memberinfos(array_list<MemberInfo*>& out, TypeBinding attr)
108102
{
109103
for (auto& [name, info] : this->member_infos_)

CoreLib/Type.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ namespace JxCoreLib
285285
const std::type_info& get_typeinfo() const { return this->typeinfo_; }
286286
bool is_primitive_type() const;
287287
bool is_boxing_type() const;
288-
bool is_custom_primitive_type() const;
289288
bool is_interface() const { return this->is_interface_; }
290289
bool is_enum() const { return this->enum_getter_; }
291290
public:
@@ -351,9 +350,9 @@ namespace JxCoreLib
351350

352351
IInterface_sp GetSharedInterface(Object_rsp instance, Type* type)
353352
{
354-
for (auto& [type, func, sfunc] : this->interfaces_)
353+
for (auto& [ty, func, sfunc] : this->interfaces_)
355354
{
356-
if (type == type)
355+
if (ty == type)
357356
{
358357
return sfunc(instance);
359358
}
@@ -362,9 +361,9 @@ namespace JxCoreLib
362361
}
363362
IInterface* GetInterface(Object* instance, Type* type)
364363
{
365-
for (auto& [type, func, sfunc] : this->interfaces_)
364+
for (auto& [ty, func, sfunc] : this->interfaces_)
366365
{
367-
if (type == type)
366+
if (ty == type)
368367
{
369368
return func(instance);
370369
}

JxCode.CoreLib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ extern void TestGuid();
2525
extern void TestMath();
2626
extern void TestPlatform();
2727

28-
2928
int main()
3029
{
3130
using namespace std;
31+
3232
TestOOP();
3333
TestEnum();
3434
TestProperty();

0 commit comments

Comments
 (0)