Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'Ptr (./kdelibs/kjs/object.h:280)
class Ptr {
public:
Ptr() : obj(0L) { }
Ptr(KJSO *o) { assert(o); obj = o; }
Ptr(const Ptr &p) { /* TODO */ obj = p.obj->ref(); }
Ptr& operator=(const Ptr &p) { if (obj) obj->deref(); obj = p.obj->ref();
return *this;}
~Ptr() { if (obj) obj->deref(); }
Ptr *operator=(KJSO *o) { if (obj) obj->deref(); obj = o; return this; }
KJSO* operator->() const { return obj; }
operator KJSO*() const { return obj; }
void release() { obj->deref(); obj = 0L; }
KJSO *ref() { obj->ref(); return obj; }
private:
KJSO *obj;
};
KJSO *zeroRef(KJSO *obj);
class List;
class ListIterator;
/**
* @internal
*/
class ListNode {
friend List;
friend ListIterator;
ListNode(KJSO *obj, ListNode *p, ListNode *n)
: member(obj), prev(p), next(n) {};
~ListNode() { if (member) member->deref(); }
KJSO *member;
ListNode *prev, *next;
};
/**
* @short Iterator for @ref KJS::List objects.
*/
class ListIterator {
friend List;
ListIterator();
ListIterator(const ListNode *n) : node(n) { }
public:
/**
* Construct an iterator that points to the first element of the list.
* @param l The list the iterator will operate on.
*/
ListIterator(const List &list);
/**
* Assignment constructor.
*/
ListIterator& operator=(const ListIterator &iterator)
{ node=iterator.node; return *this; }
/**
* Copy constructor.
*/
ListIterator(const ListIterator &i) : node(i.node) { }
/**
* Dereference the iterator.
* @return A pointer to the element the iterator operates on.
*/
KJSO* operator->() const { return node->member; }
/**
* Conversion to @ref KJS::KJSO*
* @return A pointer to the element the iterator operates on.
*/
operator KJSO*() const { return node->member; }
/**
* Postfix increment operator.
* @return The element after the increment.
*/
KJSO* operator++() { node = node->next; return node->member; }
/**
* Prefix increment operator.
*/
KJSO* operator++(int) { const ListNode *n = node; ++*this; return n->member; }
/**
* Postfix decrement operator.
*/
KJSO* operator--() { node = node->prev; return node->member; }
/**
* Prefix decrement operator.
*/
KJSO* operator--(int) { const ListNode *n = node; --*this; return n->member; }
/**
* Compare the iterator with another one.
* @return True if the two iterators operate on the same list element.
* False otherwise.
*/
bool operator==(const ListIterator &it) const { return (node==it.node); }
/**
* Check for inequality with another iterator.
* @return True if the two iterators operate on different list elements.
*/
bool operator!=(const ListIterator &it) const { return (node!=it.node); }
private:
const ListNode *node;
};
/**
* @short Native list type.
*
* List is a native ECMAScript type. List values are only used for
* intermediate results of expression evaluation and cannot be stored
* as properties of objects.
*
* The class takes care of memory management via reference counting.
*/
class List : public KJSO {
friend ListIterator;
public:
/**
* Constructor.
*/
List();
/**
* Destructor.
*/
~List();
/**
* @return KJS::ListType
*/
Type type() const { return ListType; }
/**
* Append an object to the end of the list.
*
* @param obj Pointer to object.
*/
void append(KJSO *obj);
/**
* Insert an object at the beginning of the list.
*
* @param obj Pointer to object.
*/
void prepend(KJSO *obj);
/**
* Remove the element at the beginning of the list.
*/
void removeFirst();
/**
* Remove the element at the end of the list.
*/
void removeLast();
/**
* Remove all elements from the list.
*/
void clear();
/**
* @return A @ref KJS::ListIterator pointing to the first element.
*/
ListIterator begin() const { return ListIterator(hook->next); }
/**
* @return A @ref KJS::ListIterator pointing to the last element.
*/
ListIterator end() const { return ListIterator(hook); }
/**
* @return true if the list is empty. false otherwise.
*/
bool isEmpty() const { return (hook->prev == hook); }
/**
* @return the current size of the list.
*/
int size() const;
/**
* Retrieve an element at an indexed position. If you want to iterate
* trough the whole list using @ref KJS::ListIterator will be faster.
*
* @param i List index.
* @return Pointer to the element at position i. @ref KJS::Undefined if the
* index is out of range.
*/
KJSO *at(int i) const;
/**
* Equivalent to @ref at.
*/
KJSO *operator[](int i) const { return at(i); }
/**
* Returns a pointer to a static instance of an empty list. Useful if a
* function has a @ref KJS::List parameter.
*/
static const List *empty();
private:
void erase(ListNode *n);
ListNode *hook;
static List *emptyList;
};
/**
* @short Object class encapsulating an internal value.
*/
class Object : public KJSO {
public:
Object(Class c = UndefClass, KJSO *v = 0L, Object *p = 0L);
~Object() { if (objValue) objValue->deref(); }
Type type() const { return ObjectType; }
void setClass(Class c) { classType = c; }
Class getClass() const { return classType; }
void setInternalValue(KJSO *v) { objValue = v ? v->ref() : 0L; }
KJSO *internalValue() { return objValue->ref(); }
static Object *create(Class c, KJSO *val = 0L, Object *p = 0L);
private:
Class classType;
KJSO* objValue;
};
/**
* @short Base class for language extensions.
*/
class HostObject : public KJSO {
public:
virtual Type type() const { return HostType; }
virtual KJSO *get(const UString &p);
virtual void put(const UString &p, KJSO *v);
};
/**
* @short Unique global object containing initial native properties.
*/
class Global : public KJSO {
public:
Global();
Type type() const { return ObjectType; }
Object *objProto;
Object *funcProto;
Object *arrayProto;
Object *stringProto;
Object *booleanProto;
Object *numberProto;
Object *dateProto;
Object *regexpProto;
Object *errorProto;
Object *evalErrorProto;
Object *rangeErrorProto;
Object *refErrorProto;
Object *syntaxErrorProto;
Object *typeErrorProto;
Object *uriErrorProto;
private:
class GlobalInternal;
GlobalInternal *internal;
};
}; // namespace