Kross::Api::ListT< OBJECT, TYPE > Class Template Reference

#include <list.h>

Inheritance diagram for Kross::Api::ListT< OBJECT, TYPE >:

Inheritance graph
[legend]
Collaboration diagram for Kross::Api::ListT< OBJECT, TYPE >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class OBJECT, class TYPE>
class Kross::Api::ListT< OBJECT, TYPE >

This template class extends the List class with a more generic way to deal with lists.

Definition at line 105 of file list.h.

Public Types

typedef KSharedPtr< ListPtr

Public Member Functions

 ListT (QValueList< TYPE > values)
 ListT (QIntDict< TYPE > values)
 ListT (const QPtrList< TYPE > values)
virtual ~ListT ()
virtual const QString getClassName () const
virtual const QString toString ()
Object::Ptr item (uint idx)
uint count ()
void append (Object::Ptr object)
V & getValue ()
const QStringgetName () const
Object::Ptr getParent () const
bool hasChild (const QString &name) const
Object::Ptr getChild (const QString &name) const
QMap< QString, Object::PtrgetChildren () const
bool addChild (Object::Ptr object, const QString &name=QString::null)
void removeChild (const QString &name)
void removeAllChildren ()
virtual Object::Ptr call (const QString &name, KSharedPtr< List > arguments)
virtual QStringList getCalls ()

Static Public Member Functions

template<class T>
static T * fromObject (Object::Ptr object)

Friends

class Value< List, QValueList< Object::Ptr > >


Member Typedef Documentation

typedef KSharedPtr<List> Kross::Api::List::Ptr [inherited]
 

Shared pointer to implement reference-counting.

Reimplemented from Kross::Api::Object.

Definition at line 44 of file list.h.


Member Function Documentation

bool Object::addChild Object::Ptr  object,
const QString name = QString::null
[inherited]
 

Add a new child. Replaces a possible already existing child with such a name.

Parameters:
name the name of the child
object The Object to add.
Returns:
true if the Object was added successfully else false.

Definition at line 79 of file object.cpp.

References QString::arg(), QString::isEmpty(), QString::isNull(), and QMap::replace().

Referenced by Kross::Api::MainModule::addKAction(), Kross::Api::MainModule::addQObject(), Kross::Api::MainModule::addSignal(), Kross::Api::MainModule::addSlot(), Kross::Api::QtObject::QtObject(), and TestPluginModule::TestPluginModule().

00080 {
00081     QString n = name.isNull() ? object->getName() : name;
00082 
00083 #ifdef KROSS_API_OBJECT_ADDCHILD_DEBUG
00084     kdDebug() << QString("Kross::Api::Object::addChild() object.name='%2' object.classname='%3'")
00085         .arg(n).arg(object->getClassName()) << endl;
00086 #endif
00087 
00088     if(n.isEmpty()) // prevent invalid items.
00089         return false; //throw Exception::Ptr( new Exception( QString("Failed to add child object to object '%1'. Invalid name for class '%2'.").arg(getName()).arg(object->getClassName()) ) );
00090 
00091     object->m_parent = this;
00092     m_children.replace(n, object);
00093     return true;
00094 }

void List::append Object::Ptr  object  )  [inherited]
 

Append an Kross::Api::Object to the list.

Parameters:
object The Kross::Api::Object instance to append to this list.

Definition at line 65 of file list.cpp.

References Kross::Api::Value< T, V >::getValue().

Referenced by Kross::Api::ListT< OBJECT, TYPE >::ListT().

00066 {
00067     getValue().append(object);
00068 }

virtual Object::Ptr Kross::Api::Object::call const QString name,
KSharedPtr< List arguments
[virtual, inherited]
 

Pass a call to the object and evaluated it recursive down the object-hierachy. Objects like Class are able to handle call's by just implementing this function. If the call is done the called() method will be executed recursive from bottom up the call hierachy.

Exceptions:
TypeException if the object or the name is not callable.
Parameters:
name Each call has a name that says what should be called. In the case of a Class the name is the functionname.
arguments The list of arguments passed to the call.
Returns:
The call-result as Object::Ptr instance or NULL if the call has no result.

Reimplemented in Kross::Api::EventScript, Kross::Api::EventSignal, and Kross::Api::EventSlot.

Referenced by Kross::Api::Callable::call(), and Kross::Api::Callable::callChild().

uint List::count  )  [inherited]
 

Return the number of items in the QValueList this list holds.

Returns:
The number of items.

Definition at line 60 of file list.cpp.

References Kross::Api::Value< T, V >::getValue().

00061 {
00062     return getValue().count();
00063 }

template<class T>
static T* Kross::Api::Object::fromObject Object::Ptr  object  )  [inline, static, inherited]
 

Try to convert the Object instance to the template class T.

Exceptions:
TypeException if the cast failed.
Parameters:
object The Object to cast.
Returns:
The to a instance from template type T casted Object.

Definition at line 198 of file object.h.

00199             {
00200                 T* t = (T*) object.data();
00201                 if(! t)
00202                     throw KSharedPtr<Exception>( new Exception(QString("Object \"%1\" invalid.").arg(object ? object->getClassName() : "")) );
00203                 return t;
00204             }

virtual QStringList Kross::Api::Object::getCalls  )  [inline, virtual, inherited]
 

Return a list of supported callable objects.

Returns:
List of supported calls.

Reimplemented in Kross::Python::PythonObject.

Definition at line 186 of file object.h.

00186 { return QStringList(); }

Object::Ptr Object::getChild const QString name  )  const [inherited]
 

Return the defined child or NULL if there is no such object with that name avaible.

Parameters:
name The name of the Object to return.
Returns:
The Object matching to the defined name or NULL if there is no such Object.

Definition at line 69 of file object.cpp.

Referenced by Kross::Api::Callable::getChild().

00070 {
00071     return m_children[name];
00072 }

QMap< QString, Object::Ptr > Object::getChildren  )  const [inherited]
 

Return all children.

Returns:
A ObjectMap of children this Object has.

Definition at line 74 of file object.cpp.

Referenced by Kross::Api::Callable::getChildrenDict(), and Kross::Api::Callable::getChildrenList().

00075 {
00076     return m_children;
00077 }

const QString List::getClassName  )  const [virtual, inherited]
 

See

See also:
Kross::Api::Object::getClassName()

Implements Kross::Api::Object.

Definition at line 36 of file list.cpp.

00037 {
00038     return "Kross::Api::List";
00039 }

const QString & Object::getName  )  const [inherited]
 

Return the name this object has.

Returns:
Name of this object.

Reimplemented in Kross::Api::ScriptContainer.

Definition at line 49 of file object.cpp.

Referenced by Kross::Api::Event< QtObject >::call(), Kross::Api::Callable::call(), Kross::Api::Callable::getChild(), and Kross::Api::Module::~Module().

00050 {
00051     return m_name;
00052 }

Object::Ptr Object::getParent  )  const [inherited]
 

Return the parent object or NULL if this object doesn't has a parent.

Returns:
The parent-Object or NULL if this Object doesn't has a parent.

Definition at line 59 of file object.cpp.

00060 {
00061     return m_parent;
00062 }

template<class T, class V>
V& Kross::Api::Value< T, V >::getValue  )  [inline, inherited]
 

Return the value.

Returns:
The value this Value-class holds.

Definition at line 66 of file value.h.

Referenced by Kross::Api::List::append(), Kross::Api::List::count(), Kross::Api::List::item(), Kross::Api::Variant::operator bool(), Kross::Api::Variant::operator const char *(), Kross::Api::Variant::operator const QCString(), Kross::Api::Variant::operator const QCString &(), Kross::Api::Variant::operator const QString(), Kross::Api::Variant::operator const QString &(), Kross::Api::Variant::operator const QVariant &(), Kross::Api::Variant::operator double(), Kross::Api::Variant::operator int(), Kross::Api::Variant::operator QCString(), Kross::Api::Variant::operator QString(), Kross::Api::Variant::operator uint(), Kross::Api::Variant::toList(), Kross::Api::Variant::toString(), Kross::Api::List::toString(), Kross::Api::Dict::toString(), and Kross::Api::Variant::toVariant().

00066 { return m_value; }

bool Object::hasChild const QString name  )  const [inherited]
 

Returns if the defined child is avaible.

Returns:
true if child exists else false.

Reimplemented in Kross::Api::MainModule.

Definition at line 64 of file object.cpp.

References QMap::contains().

Referenced by Kross::Api::MainModule::hasChild(), and Kross::Api::Callable::hasChild().

00065 {
00066     return m_children.contains(name);
00067 }

Object::Ptr List::item uint  idx  )  [inherited]
 

Return the Object with defined index from the QValueList this list holds.

Exceptions:
TypeException If index is out of bounds.
Parameters:
idx The QValueList-index.
Returns:
The Object instance.

Definition at line 50 of file list.cpp.

References QValueList::count(), and Kross::Api::Value< T, V >::getValue().

00051 {
00052     QValueList<Object::Ptr>& list = getValue();
00053     if(idx >= list.count()) {
00054         kdDebug() << "List::item index=" << idx << " is out of bounds. Raising TypeException." << endl;
00055         throw Exception::Ptr( new Exception(QString("List-index %1 out of bounds.").arg(idx)) );
00056     }
00057     return list[idx];
00058 }

void Object::removeAllChildren  )  [inherited]
 

Remove all children.

Definition at line 104 of file object.cpp.

References QMap::clear().

00105 {
00106 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG
00107     kdDebug() << "Kross::Api::Object::removeAllChildren()" << endl;
00108 #endif
00109     m_children.clear();
00110 }

void Object::removeChild const QString name  )  [inherited]
 

Remove an existing child.

Parameters:
name The name of the Object to remove. If there doesn't exists an Object with such name just nothing will be done.

Definition at line 96 of file object.cpp.

References QMap::remove().

00097 {
00098 #ifdef KROSS_API_OBJECT_REMCHILD_DEBUG
00099     kdDebug() << QString("Kross::Api::Object::removeChild() name='%1'").arg(name) << endl;
00100 #endif
00101     m_children.remove(name);
00102 }

const QString List::toString  )  [virtual, inherited]
 

Returns:
a string representation of the whole list.
See also:
Kross::Api::Object::toString()

Reimplemented from Kross::Api::Object.

Definition at line 41 of file list.cpp.

References QValueList::begin(), QValueList::end(), QString::endsWith(), Kross::Api::Value< T, V >::getValue(), QString::left(), and QString::length().

00042 {
00043     QString s = "[";
00044     QValueList<Object::Ptr> list = getValue();
00045     for(QValueList<Object::Ptr>::Iterator it = list.begin(); it != list.end(); ++it)
00046         s += "'" + (*it)->toString() + "', ";
00047     return (s.endsWith(", ") ? s.left(s.length() - 2) : s) + "]";
00048 }


The documentation for this class was generated from the following file:
Generated on Thu Feb 9 18:00:25 2006 for Kross by  doxygen 1.4.6