summaryrefslogtreecommitdiff
path: root/src/examples/eina_cxx
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-02-25 17:24:32 -0300
committerCedric Bail <cedric.bail@free.fr>2014-02-25 18:05:01 -0300
commitf279225a6300063c0bc6a47dedd3036ac72e89a6 (patch)
tree796dadba6c7cfaf301f89b24086a1d05647825b7 /src/examples/eina_cxx
parentd63507446fcd9ee1fd90373f5d1207f71cfb8f74 (diff)
eina: add a C++ bindings to Eina @feature.
The goal of this library is to make the life of C++ developers easier when having to manipulate Eina datatype by providing a layer to abstract those data type in C++. Check examples for now. Documentation will come soon, but we are pushing that rather sooner to get feedback on those bindings. As you will notice, this library is just composed of headers. There is no .so and we do think it is better this way. Reducing ABI and API stability issue for applications developers who are the primary target of this binding. Also please note that you will need to have C++11 to use this binding. Signed-off-by: Cedric Bail <cedric.bail@free.fr>
Diffstat (limited to 'src/examples/eina_cxx')
-rw-r--r--src/examples/eina_cxx/Makefile.am45
-rw-r--r--src/examples/eina_cxx/eina_cxx_list_01.cc55
-rw-r--r--src/examples/eina_cxx/eina_cxx_thread_01.cc32
3 files changed, 132 insertions, 0 deletions
diff --git a/src/examples/eina_cxx/Makefile.am b/src/examples/eina_cxx/Makefile.am
new file mode 100644
index 0000000000..6f784b08a1
--- /dev/null
+++ b/src/examples/eina_cxx/Makefile.am
@@ -0,0 +1,45 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_builddir)/src/lib/efl \
5-I. \
6-I$(top_srcdir)/src/lib/eina \
7-I$(top_builddir)/src/lib/eina \
8-I$(top_srcdir)/src/lib/eina_cxx \
9-I$(top_builddir)/src/lib/eina_cxx
10
11LDADD = $(top_builddir)/src/lib/eina/libeina.la @EINA_LDFLAGS@ @USE_BOOST_SYSTEM_LIBS@ @USE_BOOST_SYSTEM_LDFLAGS@
12AM_CXXFLAGS = @USE_BOOST_CPPFLAGS@
13
14SRCS = \
15eina_cxx_list_01.cc
16
17EXTRA_PROGRAMS = \
18eina_cxx_list_01 \
19eina_cxx_thread_01
20
21eina_cxx_list_01_SOURCES = \
22eina_cxx_list_01.cc
23
24eina_cxx_thread_01_SOURCES = \
25eina_cxx_thread_01.cc
26
27EXTRA_DIST = $(DATA_FILES)
28
29examples: $(EXTRA_PROGRAMS)
30
31clean-local:
32 rm -f $(EXTRA_PROGRAMS)
33
34install-examples:
35 mkdir -p $(datadir)/eina/examples
36 $(install_sh_DATA) -c $(SRCS) $(DATA_FILES) $(datadir)/eina/examples
37
38uninstall-local:
39 for f in $(SRCS) $(DATA_FILES); do \
40 rm -f $(datadir)/eina/examples/$$f ; \
41 done
42
43if ALWAYS_BUILD_EXAMPLES
44noinst_PROGRAMS = $(EXTRA_PROGRAMS)
45endif
diff --git a/src/examples/eina_cxx/eina_cxx_list_01.cc b/src/examples/eina_cxx/eina_cxx_list_01.cc
new file mode 100644
index 0000000000..b451ef1553
--- /dev/null
+++ b/src/examples/eina_cxx/eina_cxx_list_01.cc
@@ -0,0 +1,55 @@
1//Compile with:
2//gcc -g eina_list_01.c -o eina_list_01 `pkg-config --cflags --libs eina`
3
4#include <stdio.h>
5#include <Eina.hh>
6
7#include <iterator>
8#include <algorithm>
9
10#include <iostream>
11
12template <typename I>
13I next(I i, std::size_t n = 1u)
14{
15 for(;n;--n)
16 ++i;
17}
18
19int main(int argc, char **argv)
20{
21 efl::eina::eina_init eina_init;
22
23 efl::eina::ptr_list<std::string, efl::eina::heap_copy_allocator> list;
24
25 list.push_back("tigh");
26 list.push_back("adar");
27 list.push_back("baltar");
28 list.push_back("roslin");
29
30 for(efl::eina::ptr_list<std::string>::const_iterator
31 first = list.begin(), last = list.end()
32 ;first != last; ++first)
33 std::cout << *first << std::endl;
34
35 efl::eina::ptr_list<std::string>::iterator
36 iterator = ::next(list.begin(), 2u);
37 list.insert(iterator, "cain");
38
39 iterator = std::find(list.begin(), list.end(), "cain");
40 assert(iterator != list.end() && ::next(iterator) != list.end());
41 list.insert(::next(iterator), "zarek");
42
43 list.insert(list.begin(), "adama");
44
45 iterator = std::find(list.begin(), list.end(), "cain");
46 assert(iterator != list.end());
47 list.insert(iterator, "gaeta");
48
49 list.insert(::next(list.begin()), "lampkin");
50
51 for(efl::eina::ptr_list<std::string>::const_iterator
52 first = list.begin(), last = list.end()
53 ;first != last; ++first)
54 std::cout << *first << std::endl;
55}
diff --git a/src/examples/eina_cxx/eina_cxx_thread_01.cc b/src/examples/eina_cxx/eina_cxx_thread_01.cc
new file mode 100644
index 0000000000..6ce329f3e5
--- /dev/null
+++ b/src/examples/eina_cxx/eina_cxx_thread_01.cc
@@ -0,0 +1,32 @@
1//Compile with:
2//gcc -g eina_list_01.c -o eina_list_01 `pkg-config --cflags --libs eina`
3
4#include <stdio.h>
5#include <Eina.hh>
6
7#include <iterator>
8#include <algorithm>
9
10#include <iostream>
11
12namespace eina = efl::eina;
13
14void thread1(eina::mutex& m)
15{
16
17}
18
19int main(int argc, char **argv)
20{
21 eina::eina_init eina_init;
22 eina::eina_threads_init threads_init;
23
24 eina::mutex m;
25 eina::condition_variable c;
26
27 eina::unique_lock<eina::mutex> l(m);
28
29 eina::thread thread1(&::thread1, eina::ref(m));
30
31 thread1.join();
32}