Bond
 
Loading...
Searching...
No Matches
debug.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8#include "omit_default.h"
9
10namespace bond
11{
12
13namespace detail
14{
15
16template <typename T>
17class OptionalDefault : boost::noncopyable
18{
19public:
20 OptionalDefault(const T& var)
21 : _var(var),
22 _default(true)
23 {
24 boost::mpl::for_each<typename schema<T>::type::fields>(boost::ref(*this));
25 }
26
27 operator bool()
28 {
29 return _default;
30 }
31
32 template <typename Field>
33 typename boost::enable_if_c<!is_bond_type<typename Field::field_type>::value
34 && std::is_same<typename Field::field_modifier,
35 reflection::optional_field_modifier>::value>::type
36 operator()(const Field&)
37 {
38 _default = _default && is_default(Field::GetVariable(_var), Field::metadata);
39 }
40
41
42 template <typename Field>
43 typename boost::disable_if_c<!is_bond_type<typename Field::field_type>::value
44 && std::is_same<typename Field::field_modifier,
45 reflection::optional_field_modifier>::value>::type
46 operator()(const Field&)
47 {}
48
49private:
50 const T& _var;
51 bool _default;
52};
53
54
55} // namespace detail
56
57} // namespace bond
namespace bond
Definition: apply.h:17