- introduced new smart pointer class

- used it in some places for testing

SVN revision: 38170
This commit is contained in:
Andreas Volz 2008-12-16 23:01:53 +00:00
parent d338e3c09a
commit 1bf608241d
6 changed files with 131 additions and 21 deletions

View File

@ -17,6 +17,7 @@ libeflpp_include_DATA = \
eflpp_common.h\
eflpp_debug.h\
eflpp_debug_internal.h\
eflpp_sys.h
eflpp_sys.h\
eflpp_countedptr.h
EXTRA_DIST = $(libeflpp_include_DATA)

View File

@ -0,0 +1,80 @@
/*
* The following code example is taken from the book
* The C++ Standard Library - A Tutorial and Reference
* by Nicolai M. Josuttis, Addison-Wesley, 1999
* © Copyright Nicolai M. Josuttis 1999
*/
#ifndef COUNTEDPTR_H
#define COUNTEDPTR_H
namespace efl {
/* class for counted reference semantics
* - deletes the object to which it refers when the last CountedPtr
* that refers to it is destroyed
*/
template <class T>
class CountedPtr {
private:
T* ptr; // pointer to the value
long* count; // shared number of owners
public:
// initialize pointer with existing pointer
// - requires that the pointer p is a return value of new
explicit CountedPtr (T* p=0)
: ptr(p), count(new long(1))
{
}
// copy pointer (one more owner)
CountedPtr (const CountedPtr<T>& p) throw()
: ptr(p.ptr), count(p.count)
{
++*count;
}
// destructor (delete value if this was the last owner)
~CountedPtr () throw()
{
dispose();
}
// assignment (unshare old and share new value)
CountedPtr<T>& operator= (const CountedPtr<T>& p) throw()
{
if (this != &p) {
dispose();
ptr = p.ptr;
count = p.count;
++*count;
}
return *this;
}
// access the value to which the pointer refers
T& operator*() const throw()
{
return *ptr;
}
T* operator->() const throw()
{
return ptr;
}
private:
void dispose()
{
if (--*count == 0)
{
delete count;
delete ptr;
}
}
};
} // end namespace elf
#endif /*COUNTEDPTR_H*/

View File

@ -3,9 +3,9 @@
#include <iostream>
#include <cassert>
#include <string>
using std::cerr;
using std::endl;
using namespace std;
namespace efl {
@ -55,14 +55,13 @@ EvasEdje::EvasEdje( int x, int y, const char* filename, const char* groupname, E
#endif
setFile( filename, groupname );
move( x, y );
//_size = size();
//resize( _size );
}
/*EvasEdje::EvasEdje( Evas_Object* object, EvasCanvas* canvas, const char* name )
EvasEdje::EvasEdje( Evas_Object* object)
{
o = object;
}*/
mManaged = false;
}
bool EvasEdje::setFile( const char* filename, const char* groupname )
{
@ -143,6 +142,11 @@ void EvasEdje::_edje_signal_handler_callback( void *data, Evas_Object *obj, cons
else Dout( dc::warning, "EvasEdje::_edje_signal_handler_callback() - got callback without valid signal" );
}
EvasEdje* EvasEdje::wrap( Evas_Object* o )
{
return new EvasEdje( o );
}
//===============================================================================================
// EdjePart
//===============================================================================================
@ -187,15 +191,24 @@ void EdjePart::unswallow( EvasObject* object )
edje_object_part_unswallow( _parent->obj(), object->obj() );
}
Evas_Object* EdjePart::swallow()
CountedPtr <EvasObject> EdjePart::swallow()
{
return edje_object_part_swallow_get( _parent->obj(), _partname );//, _parent->canvas ();
Evas_Object *eo = edje_object_part_swallow_get( _parent->obj(), _partname );
const char *t = evas_object_type_get( eo );
EvasObject *ret_o = NULL;
if (t == string ("edje"))
{
ret_o = EvasEdje::wrap (eo);
}
return CountedPtr <EvasObject> (ret_o);
}
const EvasObject* EdjePart::getObject ( const char* name )
/*const EvasObject* EdjePart::getObject ( const char* name )
{
return EvasObject::objectLink( edje_object_part_object_get( static_cast <const Evas_Object*> (_parent->obj()), name ) );
}
}*/
} // end namespace efl

View File

@ -9,6 +9,7 @@
#include <eflpp_evas.h>
#include <eflpp_evasutils.h>
#include <eflpp_common.h>
#include <eflpp_countedptr.h>
/* EFL */
#include <Edje.h>
@ -106,9 +107,9 @@ class EdjePart
void swallow( EvasObject* );
void unswallow( EvasObject* );
Evas_Object* swallow();
CountedPtr <EvasObject> swallow();
const EvasObject* getObject ( const char* name );
//const EvasObject* getObject ( const char* name );
private:
EvasEdje* _parent;
@ -151,11 +152,6 @@ class EvasEdje : public EvasObject
EvasEdje( const char* filename, const char* groupname, EvasCanvas* canvas, const char* name = 0 );
EvasEdje( int x, int y, const char* filename, const char* groupname, EvasCanvas* canvas, const char* name = 0 );
/*!
* Connect to existing Evas_Object
*/
//EvasEdje( Evas_Object* object, EvasCanvas* canvas, const char* name = 0 );
~EvasEdje();
/*
@ -208,6 +204,8 @@ class EvasEdje : public EvasObject
/* signals and slots */
void connect( const char* emission, const char* source, const EdjeSignalSlot& slot );
void emit( const char* emission, const char* source );
static EvasEdje *wrap( Evas_Object* o );
protected:
mutable EdjePartMap _parts;
@ -218,6 +216,9 @@ class EvasEdje : public EvasObject
EvasEdje();
EvasEdje( const EvasEdje& );
EvasEdje( Evas_Object* object );
bool operator=( const EvasEdje& );
bool operator==( const EvasEdje& );
};

View File

@ -205,6 +205,9 @@ EvasObject::EvasObject (Evas_Object *eo)
void EvasObject::init (const char *name)
{
setName( name );
// TODO: do this in a constructor?
mManaged = true;
/* Set up magic object back link */
evas_object_data_set( o, "obj_c++", this );
@ -216,7 +219,11 @@ void EvasObject::init (const char *name)
EvasObject::~EvasObject()
{
Dout( dc::notice, *this << " EvasObject::~EvasObject" );
evas_object_del( o );
if( mManaged )
{
evas_object_del( o );
}
}
const char* EvasObject::name() const
@ -230,6 +237,11 @@ void EvasObject::setName( const char* name )
evas_object_name_set( o, name );
}
const char* EvasObject::type () const
{
return evas_object_type_get( o );
}
void EvasObject::move( const Point& point )
{
move( point.x(), point.y() );

View File

@ -110,6 +110,7 @@ class EvasObject
friend class EdjePart;
protected:
EvasObject () {}
// construction/destruction
//EvasObject( EvasCanvas* canvas,
// const char* name = "(null)" );
@ -119,7 +120,7 @@ class EvasObject
* Construct from existing Evas_Object
*/
EvasObject (Evas_Object *eo);
EvasObject () {}
virtual ~EvasObject();
bool operator==(const EvasObject& rhs) { return rhs.o == o; };
@ -149,6 +150,8 @@ class EvasObject
/* Name */
const char* name() const;
void setName( const char* name );
const char* type () const;
/* Geometry */
virtual const Size size() const;
@ -205,7 +208,7 @@ class EvasObject
protected:
Evas_Object* o;
//EvasCanvas* _canvas;
bool mManaged;
void init (const char *name);