Skip to content

Commit

Permalink
Merge pull request #251 from reckfullol/master
Browse files Browse the repository at this point in the history
LLBC_Variant支持LLBC_CString
  • Loading branch information
lailongwei authored Apr 13, 2024
2 parents 96a91e4 + 5d962cd commit 250e3ef
Show file tree
Hide file tree
Showing 10 changed files with 771 additions and 687 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.2)
project(llbc)

# Set project c++ standard.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 11)

# Set project cmake options.
set(CMAKE_VERBOSE_MAKEFILE on)
Expand Down
12 changes: 6 additions & 6 deletions iOSBuild/testsuite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
D87A14F61DA3559100DB1F62 /* TestCase_Core_Utils_Misc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14AD1DA3559100DB1F62 /* TestCase_Core_Utils_Misc.cpp */; };
D87A14F71DA3559100DB1F62 /* TestCase_Core_Utils_Network.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14AF1DA3559100DB1F62 /* TestCase_Core_Utils_Network.cpp */; };
D87A14F81DA3559100DB1F62 /* TestCase_Core_Utils_Text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14B11DA3559100DB1F62 /* TestCase_Core_Utils_Text.cpp */; };
D87A14F91DA3559100DB1F62 /* TestCase_Core_VariantTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14B41DA3559100DB1F62 /* TestCase_Core_VariantTest.cpp */; };
D87A14F91DA3559100DB1F62 /* TestCase_Core_Variant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14B41DA3559100DB1F62 /* TestCase_Core_Variant.cpp */; };
D87A14FA1DA3559100DB1F62 /* TestCase_ObjBase_Array.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14B71DA3559100DB1F62 /* TestCase_ObjBase_Array.cpp */; };
D87A14FB1DA3559100DB1F62 /* TestCase_ObjBase_Dictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14B91DA3559100DB1F62 /* TestCase_ObjBase_Dictionary.cpp */; };
D87A14FC1DA3559100DB1F62 /* TestCase_ObjBase_Object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D87A14BB1DA3559100DB1F62 /* TestCase_ObjBase_Object.cpp */; };
Expand Down Expand Up @@ -199,8 +199,8 @@
D87A14B01DA3559100DB1F62 /* TestCase_Core_Utils_Network.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestCase_Core_Utils_Network.h; sourceTree = "<group>"; };
D87A14B11DA3559100DB1F62 /* TestCase_Core_Utils_Text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestCase_Core_Utils_Text.cpp; sourceTree = "<group>"; };
D87A14B21DA3559100DB1F62 /* TestCase_Core_Utils_Text.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestCase_Core_Utils_Text.h; sourceTree = "<group>"; };
D87A14B41DA3559100DB1F62 /* TestCase_Core_VariantTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestCase_Core_VariantTest.cpp; sourceTree = "<group>"; };
D87A14B51DA3559100DB1F62 /* TestCase_Core_VariantTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestCase_Core_VariantTest.h; sourceTree = "<group>"; };
D87A14B41DA3559100DB1F62 /* TestCase_Core_Variant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestCase_Core_Variant.cpp; sourceTree = "<group>"; };
D87A14B51DA3559100DB1F62 /* TestCase_Core_Variant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestCase_Core_Variant.h; sourceTree = "<group>"; };
D87A14B71DA3559100DB1F62 /* TestCase_ObjBase_Array.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestCase_ObjBase_Array.cpp; sourceTree = "<group>"; };
D87A14B81DA3559100DB1F62 /* TestCase_ObjBase_Array.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestCase_ObjBase_Array.h; sourceTree = "<group>"; };
D87A14B91DA3559100DB1F62 /* TestCase_ObjBase_Dictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestCase_ObjBase_Dictionary.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -509,8 +509,8 @@
D87A14B31DA3559100DB1F62 /* variant */ = {
isa = PBXGroup;
children = (
D87A14B41DA3559100DB1F62 /* TestCase_Core_VariantTest.cpp */,
D87A14B51DA3559100DB1F62 /* TestCase_Core_VariantTest.h */,
D87A14B41DA3559100DB1F62 /* TestCase_Core_Variant.cpp */,
D87A14B51DA3559100DB1F62 /* TestCase_Core_Variant.h */,
);
path = variant;
sourceTree = "<group>";
Expand Down Expand Up @@ -662,7 +662,7 @@
D87A14DD1DA3559100DB1F62 /* TestCase_Core_Helper_JVHelper.cpp in Sources */,
D87A14D91DA3559100DB1F62 /* TestCase_Core_Config_Property.cpp in Sources */,
D87A14261DA3541D00DB1F62 /* AppDelegate.mm in Sources */,
D87A14F91DA3559100DB1F62 /* TestCase_Core_VariantTest.cpp in Sources */,
D87A14F91DA3559100DB1F62 /* TestCase_Core_Variant.cpp in Sources */,
D87A14C21DA3559100DB1F62 /* TestCase_Comm_Facade.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion llbc/include/llbc/common/OSHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
#include <set>
#include <unordered_set>
#include <algorithm>
#include <limits.h>
#include <climits>
#include <limits>
#include <functional>
#include <utility>
Expand Down
3 changes: 3 additions & 0 deletions llbc/include/llbc/core/variant/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class LLBC_EXPORT LLBC_Variant
explicit LLBC_Variant(const char *str);
explicit LLBC_Variant(const std::string &str);
explicit LLBC_Variant(const LLBC_String &str);
explicit LLBC_Variant(const LLBC_CString &str);
template <typename _T1, typename _T2>
explicit LLBC_Variant(const std::pair<_T1, _T2> &pa);
explicit LLBC_Variant(const Seq &seq);
Expand Down Expand Up @@ -463,7 +464,9 @@ class LLBC_EXPORT LLBC_Variant
template <typename _T,
typename std::enable_if<std::is_enum<_T>::value, int>::type = 0>
LLBC_Variant& operator=(const _T &en);
LLBC_Variant &operator=(const std::string &str);
LLBC_Variant &operator=(const LLBC_String &str);
LLBC_Variant &operator=(const LLBC_CString &str);
template <typename _T1, typename _T2>
LLBC_Variant &operator=(const std::pair<_T1, _T2> &pa);
LLBC_Variant &operator=(const Seq &seq);
Expand Down
7 changes: 7 additions & 0 deletions llbc/include/llbc/core/variant/VariantInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ inline LLBC_Variant::LLBC_Variant(const LLBC_String &str)
_holder.data.obj.str = new LLBC_String(str.data(), str.size());
}

inline LLBC_Variant::LLBC_Variant(const LLBC_CString &str)
{
_holder.type = LLBC_VariantType::STR_DFT;
if (!str.empty())
_holder.data.obj.str = new LLBC_String(str.data(), str.size());
}

template <typename _T1, typename _T2>
LLBC_Variant::LLBC_Variant(const std::pair<_T1, _T2> &pa)
{
Expand Down
40 changes: 39 additions & 1 deletion llbc/src/core/variant/Variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ LLBC_Variant &LLBC_Variant::operator=(ulong ul)
return *this;
}

LLBC_Variant & LLBC_Variant::operator=(const char * const &str)
LLBC_Variant &LLBC_Variant::operator=(const char * const &str)
{
if (!IsStr())
{
Expand Down Expand Up @@ -823,6 +823,25 @@ LLBC_Variant &LLBC_Variant::operator=(const double &d)
return *this;
}

LLBC_Variant &LLBC_Variant::operator=(const std::string &str)
{
BecomeStr();
if (str.empty())
{
if (_holder.data.obj.str)
_holder.data.obj.str->clear();
}
else
{
if (_holder.data.obj.str)
*_holder.data.obj.str = str;
else
_holder.data.obj.str = new LLBC_String(str);
}

return *this;
}

LLBC_Variant &LLBC_Variant::operator=(const LLBC_String &str)
{
BecomeStr();
Expand All @@ -842,6 +861,25 @@ LLBC_Variant &LLBC_Variant::operator=(const LLBC_String &str)
return *this;
}

LLBC_Variant &LLBC_Variant::operator=(const LLBC_CString &str)
{
BecomeStr();
if (str.empty())
{
if (_holder.data.obj.str)
_holder.data.obj.str->clear();
}
else
{
if (_holder.data.obj.str)
*_holder.data.obj.str = str;
else
_holder.data.obj.str = new LLBC_String(str);
}

return *this;
}

LLBC_Variant &LLBC_Variant::operator=(const Seq &seq)
{
BecomeSeq();
Expand Down
2 changes: 1 addition & 1 deletion testsuite/TestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "core/helper/TestCase_Core_Helper_StlHelper.h"
#include "core/file/TestCase_Core_File_File.h"
#include "core/file/TestCase_Core_File_Directory.h"
#include "core/variant/TestCase_Core_VariantTest.h"
#include "core/variant/TestCase_Core_Variant.h"
#include "core/config/TestCase_Core_Config_Ini.h"
#include "core/config/TestCase_Core_Config_Property.h"
#include "core/time/TestCase_Core_Time_Time.h"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/TestSuiteDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ __DEFINE_TEST_CASE(TestCase_Core_Utils_Network)
__DEFINE_TEST_CASE(TestCase_Core_Helper_StlHelper)
__DEFINE_TEST_CASE(TestCase_Core_File_File)
__DEFINE_TEST_CASE(TestCase_Core_File_Directory)
__DEFINE_TEST_CASE(TestCase_Core_VariantTest)
__DEFINE_TEST_CASE(TestCase_Core_Variant)
__DEFINE_TEST_CASE(TestCase_Core_Config_Ini)
__DEFINE_TEST_CASE(TestCase_Core_Config_Property)
__DEFINE_TEST_CASE(TestCase_Core_Time_Time)
Expand Down
Loading

0 comments on commit 250e3ef

Please sign in to comment.