add Json utility class
This commit is contained in:
parent
5f31b12ee2
commit
1a5c7b02cb
|
|
@ -48,6 +48,7 @@
|
|||
<ClInclude Include="common\helper.h" />
|
||||
<ClInclude Include="common\IntrusiveList.hpp" />
|
||||
<ClInclude Include="common\IntrusivePtr.hpp" />
|
||||
<ClInclude Include="common\Json.h" />
|
||||
<ClInclude Include="common\noncopyable.hpp" />
|
||||
<ClInclude Include="common\Singleton.hpp" />
|
||||
<ClInclude Include="common\String.h" />
|
||||
|
|
|
|||
|
|
@ -240,6 +240,9 @@
|
|||
<ClInclude Include="utils\DataUtil.h">
|
||||
<Filter>utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="common\Json.h">
|
||||
<Filter>common</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ui\Button.cpp">
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../common/Json.h"
|
||||
#include "RefCounter.hpp"
|
||||
#include "SmartPtr.hpp"
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ namespace easy2d
|
|||
|
||||
inline String GetName() const { if (name_) return *name_; return String(); }
|
||||
|
||||
inline bool IsName(String const& name) const { return (name_ && (*name_ == name)); }
|
||||
inline bool IsName(String const& name) const { return (name_ && (*name_ == name)) || (name.empty() && !name_); }
|
||||
|
||||
static void StartTracingLeaks();
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace easy2d
|
|||
{
|
||||
public:
|
||||
using value_type = _Ty;
|
||||
using size_type = int;
|
||||
using size_type = std::size_t;
|
||||
using iterator = value_type * ;
|
||||
using const_iterator = const value_type*;
|
||||
using reference = value_type & ;
|
||||
|
|
@ -60,12 +60,13 @@ namespace easy2d
|
|||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
using allocator_type = typename _Alloc;
|
||||
using manager = typename _Manager;
|
||||
using initializer_list = std::initializer_list<value_type>;
|
||||
|
||||
public:
|
||||
inline Array() : size_(0), capacity_(0), data_(nullptr) { }
|
||||
inline Array(size_type count) : Array() { reserve(count); }
|
||||
inline Array(size_type count, const _Ty& val) : Array() { assign(count, val); }
|
||||
inline Array(std::initializer_list<_Ty> const& list) : Array() { assign(list); }
|
||||
inline Array(initializer_list list) : Array() { assign(list); }
|
||||
inline Array(const Array& src) : Array() { assign(src); }
|
||||
inline Array(Array&& src) : Array() { swap(src); }
|
||||
inline ~Array() { destroy(); }
|
||||
|
|
@ -75,11 +76,11 @@ namespace easy2d
|
|||
|
||||
inline Array& operator=(const Array& src) { if (&src != this) { resize(src.size_); manager::copy_data(begin(), src.cbegin(), size_); } return (*this); }
|
||||
inline Array& operator=(Array&& src) { swap(src); return *this; }
|
||||
inline Array& operator=(std::initializer_list<_Ty> const& list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); }
|
||||
inline Array& operator=(initializer_list list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); }
|
||||
|
||||
inline Array& assign(size_type count, const _Ty& val) { if (count > 0) { resize(count); manager::copy_data(begin(), count, val); } else clear(); return (*this); }
|
||||
inline Array& assign(const Array& src) { return operator=(src); }
|
||||
inline Array& assign(std::initializer_list<_Ty> const& list) { return operator=(list); }
|
||||
inline Array& assign(initializer_list list) { return operator=(list); }
|
||||
|
||||
template <typename _Iter>
|
||||
inline void assign(_Iter first, _Iter last) { auto diff = std::distance(first, last); resize((size_type)diff); auto data = begin(); while (first != last) (*data++) = (*first++); }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -35,7 +35,7 @@ namespace easy2d
|
|||
public:
|
||||
// Iterator
|
||||
template <typename _Ty>
|
||||
struct _Iterator
|
||||
struct iterator_impl
|
||||
{
|
||||
using iterator_category = typename std::iterator_traits<_Ty*>::iterator_category;
|
||||
using value_type = typename std::iterator_traits<_Ty*>::value_type;
|
||||
|
|
@ -46,53 +46,53 @@ namespace easy2d
|
|||
// disable warning 4996
|
||||
using _Unchecked_type = _Ty;
|
||||
|
||||
inline _Iterator(pointer base = nullptr) : base_(base) {}
|
||||
inline iterator_impl(pointer base = nullptr) : base_(base) {}
|
||||
|
||||
inline reference operator*() const { return *base_; }
|
||||
inline pointer base() const { return base_; }
|
||||
inline reference operator*() const { return *base_; }
|
||||
inline pointer base() const { return base_; }
|
||||
|
||||
inline _Iterator& operator++() { ++base_; return (*this); }
|
||||
inline _Iterator operator++(int) { _Iterator old = (*this); ++(*this); return old; }
|
||||
inline iterator_impl& operator++() { ++base_; return (*this); }
|
||||
inline iterator_impl operator++(int) { iterator_impl old = (*this); ++(*this); return old; }
|
||||
|
||||
inline _Iterator& operator--() { --base_; return (*this); }
|
||||
inline _Iterator operator--(int) { _Iterator old = (*this); --(*this); return old; }
|
||||
inline iterator_impl& operator--() { --base_; return (*this); }
|
||||
inline iterator_impl operator--(int) { iterator_impl old = (*this); --(*this); return old; }
|
||||
|
||||
inline const _Iterator operator+(difference_type off) const { return _Iterator(base_ + off); }
|
||||
inline const _Iterator operator-(difference_type off) const { return _Iterator(base_ - off); }
|
||||
inline const iterator_impl operator+(difference_type off) const { return iterator_impl(base_ + off); }
|
||||
inline const iterator_impl operator-(difference_type off) const { return iterator_impl(base_ - off); }
|
||||
|
||||
inline _Iterator& operator+=(difference_type off) { base_ += off; return (*this); }
|
||||
inline _Iterator& operator-=(difference_type off) { base_ -= off; return (*this); }
|
||||
inline iterator_impl& operator+=(difference_type off) { base_ += off; return (*this); }
|
||||
inline iterator_impl& operator-=(difference_type off) { base_ -= off; return (*this); }
|
||||
|
||||
inline difference_type operator-(_Iterator const& other) const { return base_ - other.base_; }
|
||||
inline difference_type operator-(iterator_impl const& other) const { return base_ - other.base_; }
|
||||
|
||||
inline bool operator==(_Iterator const& other) const { return base_ == other.base_; }
|
||||
inline bool operator!=(_Iterator const& other) const { return !(*this == other); }
|
||||
inline bool operator==(iterator_impl const& other) const { return base_ == other.base_; }
|
||||
inline bool operator!=(iterator_impl const& other) const { return !(*this == other); }
|
||||
|
||||
inline bool operator<(_Iterator const& other) const { return base_ < other.base_; }
|
||||
inline bool operator<=(_Iterator const& other) const { return base_ <= other.base_; }
|
||||
inline bool operator>(_Iterator const& other) const { return base_ > other.base_; }
|
||||
inline bool operator>=(_Iterator const& other) const { return base_ >= other.base_; }
|
||||
inline bool operator<(iterator_impl const& other) const { return base_ < other.base_; }
|
||||
inline bool operator<=(iterator_impl const& other) const { return base_ <= other.base_; }
|
||||
inline bool operator>(iterator_impl const& other) const { return base_ > other.base_; }
|
||||
inline bool operator>=(iterator_impl const& other) const { return base_ >= other.base_; }
|
||||
|
||||
inline reference operator[](difference_type off) { return *(base_ + off); }
|
||||
inline const reference operator[](difference_type off) const { return *(base_ + off); }
|
||||
inline reference operator[](difference_type off) { return *(base_ + off); }
|
||||
inline const reference operator[](difference_type off) const { return *(base_ + off); }
|
||||
|
||||
inline operator bool() const { return base_ != nullptr; }
|
||||
inline operator bool() const { return base_ != nullptr; }
|
||||
|
||||
private:
|
||||
pointer base_{ nullptr };
|
||||
};
|
||||
|
||||
public:
|
||||
using value_type = wchar_t;
|
||||
using size_type = size_t;
|
||||
using reference = value_type &;
|
||||
using const_reference = const value_type &;
|
||||
using iterator = _Iterator<value_type>;
|
||||
using const_iterator = _Iterator<const value_type>;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
using traits = std::char_traits<value_type>;
|
||||
using allocator = std::allocator<value_type>;
|
||||
using value_type = wchar_t;
|
||||
using size_type = size_t;
|
||||
using reference = value_type &;
|
||||
using const_reference = const value_type &;
|
||||
using iterator = iterator_impl<value_type>;
|
||||
using const_iterator = iterator_impl<const value_type>;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
using traits = std::char_traits<value_type>;
|
||||
using allocator = std::allocator<value_type>;
|
||||
|
||||
String();
|
||||
String(const wchar_t* cstr, bool const_str = true);
|
||||
|
|
@ -422,6 +422,9 @@ namespace easy2d
|
|||
, capacity_(0)
|
||||
, str_(nullptr)
|
||||
{
|
||||
if (cstr == nullptr)
|
||||
return;
|
||||
|
||||
if (operable_)
|
||||
{
|
||||
assign(cstr, traits::length(cstr));
|
||||
|
|
|
|||
|
|
@ -48,4 +48,7 @@ namespace easy2d
|
|||
|
||||
template<typename _Kty, typename _Ty, typename... _Args>
|
||||
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>;
|
||||
|
||||
template <bool _Boolean, typename _Ty = void>
|
||||
using enable_if_t = typename std::enable_if<_Boolean, _Ty>::type;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,13 +34,14 @@
|
|||
|
||||
#include "common/Array.h"
|
||||
#include "common/String.h"
|
||||
#include "common/helper.h"
|
||||
#include "common/closure.hpp"
|
||||
#include "common/IntrusiveList.hpp"
|
||||
#include "common/IntrusivePtr.hpp"
|
||||
#include "common/ComPtr.hpp"
|
||||
#include "common/noncopyable.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "common/helper.h"
|
||||
#include "common/Json.h"
|
||||
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2013-2018 Niels Lohmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -141,7 +141,6 @@
|
|||
<ClInclude Include="Demo2.h" />
|
||||
<ClInclude Include="Demo3.h" />
|
||||
<ClInclude Include="Demo4.h" />
|
||||
<ClInclude Include="include-forwards.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\easy2d-audio\Easy2D-Audio.vcxproj">
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include-forwards.h" />
|
||||
<ClInclude Include="Demo1.h" />
|
||||
<ClInclude Include="common.h" />
|
||||
<ClInclude Include="Demo2.h" />
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
#include "Demo1.h"
|
||||
#include "Demo2.h"
|
||||
#include "Demo3.h"
|
||||
#include "Demo4.h"
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include "include-forwards.h"
|
||||
#include "Demo1.h"
|
||||
#include "Demo2.h"
|
||||
#include "Demo3.h"
|
||||
#include "Demo4.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue