Magic_Game/src/kiwano/core/common.h

103 lines
3.2 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// 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.
#pragma once
2019-10-10 15:09:38 +08:00
#include <set>
#include <map>
#include <list>
#include <queue>
2019-10-14 10:43:11 +08:00
#include <stack>
2019-10-10 15:09:38 +08:00
#include <unordered_set>
#include <unordered_map>
#include <sstream>
2019-12-17 20:47:55 +08:00
#include <3rd-party/OuterC/oc/oc.h>
#include <kiwano/macros.h>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
2019-12-17 20:47:55 +08:00
using String = oc::wstring;
2019-08-13 21:16:38 +08:00
using StringStream = std::wstringstream;
2019-08-13 21:16:38 +08:00
template <typename _Ty, typename... _Args>
2019-12-17 20:47:55 +08:00
using Vector = oc::vector<_Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _Ty, typename... _Args>
using List = std::list<_Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _Ty, typename... _Args>
using Queue = std::queue<_Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _Ty, typename... _Args>
using Set = std::set<_Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _Ty1, typename _Ty2>
using Pair = std::pair<_Ty1, _Ty2>;
template <typename _Ty, typename... _Args>
using UnorderedSet = std::unordered_set<_Ty, _Args...>;
2019-10-14 10:43:11 +08:00
template <typename _Ty, typename... _Args>
using Stack = std::stack<_Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _Kty, typename _Ty, typename... _Args>
using Map = std::map<_Kty, _Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _Kty, typename _Ty, typename... _Args>
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>;
2019-08-13 21:16:38 +08:00
template <typename _FuncTy>
2019-12-17 20:47:55 +08:00
using Function = oc::function<_FuncTy>;
2019-08-13 21:16:38 +08:00
2019-12-17 20:47:55 +08:00
using Any = oc::any;
2019-10-13 17:45:58 +08:00
2019-12-17 20:47:55 +08:00
using Json = oc::basic_json<Map, Vector, String, int, double, bool, std::allocator>;
2019-10-30 23:12:18 +08:00
template <typename _Ty>
2019-12-17 20:47:55 +08:00
using Singleton = oc::singleton<_Ty>;
2019-10-30 23:12:18 +08:00
template <typename _Ty>
2019-12-17 20:47:55 +08:00
using IntrusiveList = oc::intrusive_list<_Ty>;
2019-10-30 23:12:18 +08:00
template <typename _Ty>
2019-12-17 20:47:55 +08:00
using IntrusiveListItem = oc::intrusive_list_item<_Ty>;
2019-08-13 21:16:38 +08:00
2019-12-17 20:47:55 +08:00
template <typename _Ty, typename _RefProxyTy>
using IntrusivePtr = oc::intrusive_ptr<_Ty, _RefProxyTy>;
using Noncopyable = oc::noncopyable;
// Closure
template<typename _Ty, typename _Uty, typename _Ret, typename... _Args>
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
2019-08-13 21:16:38 +08:00
{
2019-12-17 20:47:55 +08:00
return oc::closure(ptr, func);
}
template<typename _Ty, typename _Uty, typename _Ret, typename... _Args>
inline Function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)
2019-08-13 21:16:38 +08:00
{
2019-12-17 20:47:55 +08:00
return oc::closure(ptr, func);
2019-08-13 21:16:38 +08:00
}
}