eet c++ wrapper implementation from "Jonathan MULLER" <muller.john@gmail.com>
SVN revision: 37547
This commit is contained in:
parent
0a83ed01a8
commit
c3228f58cf
|
@ -194,6 +194,8 @@ examples/angstrom/bootmanager/Makefile
|
|||
examples/evas/Makefile
|
||||
examples/evas/hash/Makefile
|
||||
examples/evas/list/Makefile
|
||||
examples/eet/Makefile
|
||||
examples/eet/simple_write_read/Makefile
|
||||
data/Makefile
|
||||
data/edjes/Makefile
|
||||
data/fonts/Makefile
|
||||
|
|
|
@ -1 +1 @@
|
|||
SUBDIRS = edje esmart etk ewl emotion ecore signals debug
|
||||
SUBDIRS = edje esmart etk ewl emotion ecore signals debug eet
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
SUBDIRS = simple_write_read
|
|
@ -0,0 +1,24 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
INCLUDES =
|
||||
|
||||
AM_CXXFLAGS =\
|
||||
@PACKAGE_CFLAGS@ \
|
||||
-I$(top_srcdir)/src/eet/ \
|
||||
-Wall
|
||||
|
||||
|
||||
bin_PROGRAMS = write_eet read_eet
|
||||
|
||||
write_eet_SOURCES = \
|
||||
write_eet.cpp
|
||||
write_eet_LDFLAGS = @PACKAGE_LIBS@
|
||||
write_eet_LDADD = $(top_builddir)/src/libeflpp.la
|
||||
write_eet_DEPENDENCIES = $(top_builddir)/src/libeflpp.la
|
||||
|
||||
|
||||
read_eet_SOURCES = \
|
||||
read_eet.cpp
|
||||
read_eet_LDFLAGS = @PACKAGE_LIBS@
|
||||
read_eet_LDADD = $(top_builddir)/src/libeflpp.la
|
||||
read_eet_DEPENDENCIES = $(top_builddir)/src/libeflpp.la
|
|
@ -0,0 +1,69 @@
|
|||
#include <eflpp_eet.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
struct A
|
||||
{
|
||||
int x;
|
||||
double d;
|
||||
char s[10];
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const A& a)
|
||||
{
|
||||
os << "x=" << a.x << " d=" << a.d << " s=" << a.s;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const efl::eet_chunk& chunk)
|
||||
{
|
||||
void *data = chunk.get ();
|
||||
os << chunk.get_key () << " ";
|
||||
|
||||
if (chunk.get_key () == "A")
|
||||
os << *reinterpret_cast<A *> (data);
|
||||
else if ((chunk.get_key () == "my_string")
|
||||
|| (chunk.get_key () == "my_string2"))
|
||||
os << reinterpret_cast<char *> (data);
|
||||
|
||||
else
|
||||
os << *reinterpret_cast<int *> (data);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
struct display_eet_file_content
|
||||
{
|
||||
void operator () (const efl::eet_chunk &chunk)
|
||||
{
|
||||
std::cout << chunk << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
eet_init();
|
||||
|
||||
efl::eet_document doc("writing_test.eet", EET_FILE_MODE_READ);
|
||||
efl::eetlist my_list (doc);
|
||||
|
||||
|
||||
//A *a = reinterpret_cast<A *> (my_list["A"]. get ());
|
||||
|
||||
//std::cout << a->x << std::endl;
|
||||
//std::cout << a->d << std::endl;
|
||||
//std::cout << a->s << std::endl;
|
||||
|
||||
//int *i = reinterpret_cast<int *> (my_list["B"]. get ());
|
||||
//std::cout << "i=" << *i << std::endl;
|
||||
|
||||
std::for_each (my_list.begin (),
|
||||
my_list.end (),
|
||||
display_eet_file_content());
|
||||
|
||||
doc.close ();
|
||||
eet_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
#include <eflpp_eet.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
struct A
|
||||
{
|
||||
int x;
|
||||
double d;
|
||||
char s[10];
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
using namespace efl;
|
||||
eet_init();
|
||||
|
||||
efl::eet_document doc("writing_test.eet", EET_FILE_MODE_WRITE);
|
||||
efl::eetlist my_list (doc);
|
||||
|
||||
int x = 2;
|
||||
std::cout << "Set x" << std::endl;
|
||||
my_list["test_int"] = x;
|
||||
std::cout << "---------" << std::endl;
|
||||
|
||||
A a;
|
||||
a.x = 5;
|
||||
a.d = 12.2;
|
||||
memset(a.s, '\0', 10);
|
||||
memcpy(a.s, "john", 10);
|
||||
|
||||
std::cout << "Set A" << std::endl;
|
||||
my_list["A"] = efl::make_data (a, true);
|
||||
std::cout << "---------" << std::endl;
|
||||
|
||||
std::cout << "Use intermediate object" << std::endl;
|
||||
const char *s = "first string";
|
||||
data_information<const char *> d = make_data(s, false, strlen (s)+1);
|
||||
my_list["my_string"] = d;
|
||||
std::cout << "---------" << std::endl;
|
||||
|
||||
|
||||
std::cout << "Use directly helper function" << std::endl;
|
||||
const char *s2 = "second string";
|
||||
my_list["my_string2"] = make_data (s2, false, strlen (s)+1);
|
||||
std::cout << "--------" << std::endl;
|
||||
|
||||
std::cout << "Set B" << std::endl;
|
||||
efl::data_information<int> t2 (2, true);
|
||||
my_list["B"] = t2;
|
||||
std::cout << "--------" << std::endl;
|
||||
|
||||
|
||||
//eet_close(ef);
|
||||
doc.close ();
|
||||
eet_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
#include "eflpp_eet.h"
|
|
@ -0,0 +1,206 @@
|
|||
#ifndef EET_BASE_H
|
||||
#define EET_BASE_H
|
||||
|
||||
//! Eet includes
|
||||
#include <Eet.h>
|
||||
|
||||
//! STL includes
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* C++ Wrapper for the Enlightenment EET
|
||||
*
|
||||
* @author Jonathan Muller <jonathan.muller@drylm.org>
|
||||
*/
|
||||
|
||||
namespace efl
|
||||
{
|
||||
struct eet_document
|
||||
{
|
||||
eet_document (const std::string &file_name, Eet_File_Mode mode):
|
||||
_ef (eet_open (file_name.c_str (), mode))
|
||||
{}
|
||||
|
||||
~eet_document () { /*eet_close (_ef);*/ }
|
||||
void close () { eet_close (_ef); }
|
||||
|
||||
Eet_File_Mode mode () { return eet_mode_get (_ef); }
|
||||
|
||||
Eet_File *get () { return _ef; }
|
||||
private:
|
||||
Eet_File *_ef;
|
||||
};
|
||||
|
||||
template <typename _Ty>
|
||||
struct data_information
|
||||
{
|
||||
data_information (_Ty data,
|
||||
bool compress = false,
|
||||
unsigned int size = sizeof (_Ty) )
|
||||
: _data (data),
|
||||
_compress (compress),
|
||||
_size (size)
|
||||
{}
|
||||
|
||||
_Ty _data;
|
||||
bool _compress;
|
||||
unsigned int _size;
|
||||
};
|
||||
|
||||
/* Helper function to avoid explicit template instantiation by the user */
|
||||
template<typename _Ty>
|
||||
data_information<_Ty>
|
||||
make_data (_Ty data, bool compress = false, unsigned int size = sizeof (_Ty))
|
||||
{
|
||||
return data_information<_Ty> (data, compress, size);
|
||||
}
|
||||
|
||||
template<typename _Ty>
|
||||
data_information<_Ty *>
|
||||
make_data (_Ty *data, bool compress = false, unsigned int size = sizeof (_Ty))
|
||||
{
|
||||
return data_information<_Ty *> (data, compress, size);
|
||||
}
|
||||
|
||||
struct eet_chunk
|
||||
{
|
||||
typedef void* ptr_type;
|
||||
typedef const ptr_type const_ptr_type;
|
||||
|
||||
eet_chunk (Eet_File *ef, const std::string &key_name)
|
||||
: _ef (ef),
|
||||
_key_name (key_name),
|
||||
_size (0),
|
||||
_data (eet_read (_ef, key_name.c_str (), &_size))
|
||||
{ }
|
||||
|
||||
~eet_chunk ()
|
||||
{
|
||||
_ef = 0;
|
||||
//free (_data);
|
||||
_data = 0;
|
||||
}
|
||||
|
||||
ptr_type
|
||||
get () const
|
||||
{ return _data; }
|
||||
|
||||
std::string
|
||||
get_key () const
|
||||
{ return _key_name; }
|
||||
|
||||
|
||||
template <typename _Ty>
|
||||
eet_chunk &
|
||||
operator = (const _Ty& raw_data)
|
||||
{
|
||||
data_information<_Ty> data_to_store = make_data (raw_data);
|
||||
operator = (data_to_store);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template<typename _Ty>
|
||||
eet_chunk&
|
||||
operator = (const data_information<_Ty>& data_to_store)
|
||||
{
|
||||
eet_write (_ef,
|
||||
_key_name.c_str (),
|
||||
&data_to_store._data,
|
||||
data_to_store._size,
|
||||
data_to_store._compress);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename _Ty>
|
||||
eet_chunk&
|
||||
operator = (const data_information<_Ty *>& data_to_store)
|
||||
{
|
||||
eet_write (_ef,
|
||||
_key_name.c_str (),
|
||||
data_to_store._data,
|
||||
data_to_store._size,
|
||||
data_to_store._compress);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
Eet_File *_ef;
|
||||
std::string _key_name;
|
||||
int _size;
|
||||
ptr_type _data;
|
||||
};
|
||||
|
||||
struct iterator :
|
||||
public std::iterator<std::forward_iterator_tag, char *, void>
|
||||
{
|
||||
|
||||
iterator (char **chunk, eet_document &doc)
|
||||
: the_chunk (chunk),
|
||||
_doc(doc)
|
||||
{}
|
||||
|
||||
|
||||
eet_chunk
|
||||
operator * () const throw ()
|
||||
{ return eet_chunk (_doc.get (), *the_chunk); }
|
||||
|
||||
bool operator == (const iterator &i)
|
||||
{ return the_chunk == i.the_chunk; }
|
||||
|
||||
bool operator != (const iterator &i)
|
||||
{ return the_chunk != i.the_chunk; }
|
||||
|
||||
iterator &operator ++ () throw ()
|
||||
{
|
||||
the_chunk = &the_chunk[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator ++ (int) throw ()
|
||||
{ iterator tem (the_chunk, _doc); ++ *this; return tem; }
|
||||
|
||||
private:
|
||||
iterator ();
|
||||
char **the_chunk;
|
||||
eet_document &_doc;
|
||||
};
|
||||
|
||||
|
||||
struct eetlist
|
||||
{
|
||||
eetlist (eet_document& doc, const std::string &filter = "*" )
|
||||
: _doc (doc),
|
||||
_list (0),
|
||||
_nb_elems (0)
|
||||
{
|
||||
_list = eet_list (_doc.get (), filter.c_str (), &_nb_elems);
|
||||
}
|
||||
|
||||
~eetlist () { free(_list); }
|
||||
|
||||
iterator begin ()
|
||||
{ return iterator(&_list[0], _doc); }
|
||||
|
||||
iterator end ()
|
||||
{ return iterator(&_list[_nb_elems], _doc); }
|
||||
|
||||
const eet_chunk
|
||||
operator [] (const std::string &key_name) const
|
||||
{ return eet_chunk (_doc.get (), key_name); }
|
||||
|
||||
eet_chunk operator [] (const std::string &key_name)
|
||||
{ return eet_chunk (_doc.get (), key_name); }
|
||||
|
||||
private:
|
||||
eet_document &_doc;
|
||||
char **_list;
|
||||
int _nb_elems;
|
||||
};
|
||||
|
||||
} //ns efl
|
||||
|
||||
|
||||
#endif //EET_BASE_H
|
Loading…
Reference in New Issue