summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/eo_class_scope_guard_generator.hh
blob: 5915c38bebffaa3505fdefa68b4ae465055abee8 (plain) (blame)
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
#ifndef EOLIAN_CXX_STD_EO_CLASS_SCOPE_GUARD_GENERATOR_HH
#define EOLIAN_CXX_STD_EO_CLASS_SCOPE_GUARD_GENERATOR_HH

#include <cassert>

#include "type_generator.hh"

namespace efl { namespace eolian { namespace grammar {

template <typename T>
struct _scope_guard_head
{
   eo_class const& _cls;
   T const& _e;
   _scope_guard_head(eo_class const& cls, T const& e)
     : _cls(cls), _e(e) {}
};

template <typename T>
_scope_guard_head<T> scope_guard_head(eo_class const& cls, T const& e)
{
   return _scope_guard_head<T>(cls, e);
}

template <typename T>
inline std::ostream&
operator<<(std::ostream& out, _scope_guard_head<T> const& x)
{
   assert(x._e.scope != eolian_scope::private_);
   if (x._e.scope == eolian_scope::protected_)
     out << "#ifdef " << name_upper(x._cls) << "_PROTECTED" << endl;
   if (x._e.is_beta)
     out << "#ifdef " << name_upper(x._cls) << "_BETA" << endl;
   return out;
}

template <typename T>
struct _scope_guard_tail
{
   eo_class const& _cls;
   T const& _e;
   _scope_guard_tail(eo_class const& cls, T const& e)
     : _cls(cls), _e(e) {}
};

template <typename T>
struct _scope_guard_tail<T> scope_guard_tail(eo_class const& cls, T const& e)
{
   return _scope_guard_tail<T>(cls, e);
}

template <typename T>
inline std::ostream&
operator<<(std::ostream& out, _scope_guard_tail<T> const& x)
{
   if (x._e.scope == eolian_scope::protected_)
     out << "#endif" << endl;
   if (x._e.is_beta)
     out << "#endif" << endl;
   return out;
}

} } }

#endif