summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/part_implementation.hpp
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-11-27 19:52:44 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-05 10:15:40 +0900
commit5901b4601e3a240f6286ab9396d1ea2967ca61bc (patch)
treedcb679ad428348da47fd2c08cab26e292419e197 /src/lib/eolian_cxx/grammar/part_implementation.hpp
parentf47bb54f4f0960b34050be4342f692f33feedf35 (diff)
cxx: Implement support for parts
This generates methods like this: Part_Class part_name() const; Which can then be used like: slider.indicator().format_string_set("%1.1f");
Diffstat (limited to '')
-rw-r--r--src/lib/eolian_cxx/grammar/part_implementation.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/lib/eolian_cxx/grammar/part_implementation.hpp b/src/lib/eolian_cxx/grammar/part_implementation.hpp
new file mode 100644
index 0000000000..cee2fc7fa8
--- /dev/null
+++ b/src/lib/eolian_cxx/grammar/part_implementation.hpp
@@ -0,0 +1,72 @@
1#ifndef EOLIAN_CXX_PART_IMPLEMENTATION_HH
2#define EOLIAN_CXX_PART_IMPLEMENTATION_HH
3
4#include "grammar/generator.hpp"
5
6#include "grammar/string.hpp"
7#include "grammar/indentation.hpp"
8#include "grammar/list.hpp"
9#include "grammar/alternative.hpp"
10#include "grammar/type.hpp"
11#include "grammar/parameter.hpp"
12#include "grammar/keyword.hpp"
13
14namespace efl { namespace eolian { namespace grammar {
15
16struct part_implementation_generator
17{
18 part_implementation_generator(std::string const& _klass_name)
19 : klass_name(_klass_name) {}
20
21 template <typename OutputIterator, typename Context>
22 bool generate(OutputIterator sink, attributes::part_def const& part, Context const& ctx) const
23 {
24 if(!as_generator("#ifdef EFL_CXXPERIMENTAL\n").generate(sink, attributes::unused, ctx))
25 return false;
26
27 if(!as_generator("::efl::eolian::return_traits<::" << *(string << "::"))
28 .generate(sink, part.klass.namespaces, add_lower_case_context(ctx)))
29 return false;
30 // FIXME: part_def can't depend on klass_def so C type is not known :(
31 if(!as_generator(string << ">::type "<< string << "::" << string << "() const\n{\n"
32 << scope_tab << "::Eo *__return_value = ::efl_part"
33 << "(this->_eo_ptr(), \"" << string << "\");\n"
34 << scope_tab << "::efl_auto_unref_set(__return_value, false);\n")
35 .generate(sink, std::make_tuple(part.klass.eolian_name, klass_name, part.name, part.name), ctx))
36 return false;
37 if(!as_generator(scope_tab << "return ::" << *(string << "::"))
38 .generate(sink, part.klass.namespaces, add_lower_case_context(ctx)))
39 return false;
40 if(!as_generator(string << "{__return_value};\n}\n")
41 .generate(sink, part.klass.eolian_name, ctx))
42 return false;
43
44 if(!as_generator("#endif\n").generate(sink, attributes::unused, ctx))
45 return false;
46
47 return true;
48 }
49
50private:
51 std::string klass_name;
52};
53
54template <>
55struct is_eager_generator<part_implementation_generator> : std::true_type {};
56
57namespace type_traits {
58template <>
59struct attributes_needed<part_implementation_generator> : std::integral_constant<int, 1> {};
60}
61
62struct part_implementation_terminal
63{
64 part_implementation_generator operator()(std::string klass_name) const
65 {
66 return part_implementation_generator{klass_name};
67 }
68} const part_implementation = {};
69
70} } }
71
72#endif