-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathVariant.hpp
68 lines (59 loc) · 2.07 KB
/
Variant.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
#ifndef MAT_VARIANT_HPP
#define MAT_VARIANT_HPP
#include "ctmacros.hpp"
#include "Enums.hpp"
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <initializer_list>
#include <cstdint>
#include <sstream>
#include <iomanip>
#include <cassert>
#ifdef VARIANT_CONCURRENCY
#ifdef _MANAGED
// Implementation of a LOCKGUARD for C++/CX .NET 4.x
#include <msclr/lock.h>
public ref class VariantLockGuard { public: static Object ^ lock = gcnew Object(); };
#define VARIANT_LOCKGUARD(lock_object) msclr::lock l(VariantLockGuard::lock);
#define VARIANT_LOCK(lock_object)
#else
#ifdef _WIN32
#include <ppl.h>
#include <concurrent_unordered_map.h>
#include <concurrent_vector.h>
#endif
// Implementation of a LOCKGUARD for C++11
#include <mutex>
#define VARIANT_LOCKGUARD(lock_object) std::lock_guard<decltype(lock_object)> TOKENPASTE2(__guard_, __LINE__) (lock_object)
#define VARIANT_LOCK(lock_object) std::recursive_mutex lock_object
#endif
#endif
namespace MAT_NS_BEGIN
{
class Variant;
#ifdef VARIANT_CONCURRENCY
// Windows provides concurrent maps and vectors as part of PPL concurrency package.
// We are not currently using it, but we may consider to use it for safe concurrent
// access to config tree from different threads at the same time.
// Base type for Object (map)
typedef concurrency::concurrent_unordered_map<std::string, Variant> VariantMap;
// Base type for Array (vector)
typedef concurrency::concurrent_vector<Variant> VariantArray;
#else
// Base type for Object (map)
typedef std::map<std::string, Variant> VariantMap;
// Base type for Array (vector)
typedef std::vector<Variant> VariantArray;
#endif
// Generic variant type implementation added to SDK namespace
#include "VariantType.hpp"
// Shortcut for VariantArray constructor
// const auto ARR = Variant::from_array;
} MAT_NS_END
#endif