All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreHashNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreHashNode.h
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QOREHASHNODE_H
#define _QORE_QOREHASHNODE_H
#include <qore/AbstractQoreNode.h>
#include <qore/common.h>
class HashMember;
class LocalVar;
class QoreHashNode : public AbstractQoreNode {
friend class HashIterator;
friend class ReverseHashIterator;
friend class ConstHashIterator;
friend class ReverseConstHashIterator;
friend class HashAssignmentHelper;
friend class hash_assignment_priv;
friend class qore_object_private;
friend class qore_hash_private;
private:
DLLLOCAL QoreHashNode(const QoreHashNode&);
DLLLOCAL QoreHashNode& operator=(const QoreHashNode&);
protected:
class qore_hash_private *priv;
DLLEXPORT virtual bool derefImpl(ExceptionSink* xsink);
DLLEXPORT virtual AbstractQoreNode* evalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual AbstractQoreNode* evalImpl(bool &needs_deref, ExceptionSink* xsink) const;
DLLLOCAL virtual int64 bigIntEvalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual int integerEvalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual bool boolEvalImpl(ExceptionSink* xsink) const;
DLLLOCAL virtual double floatEvalImpl(ExceptionSink* xsink) const;
DLLEXPORT virtual ~QoreHashNode();
public:
DLLEXPORT QoreHashNode();
DLLEXPORT virtual bool getAsBoolImpl() const;
DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
DLLEXPORT virtual QoreString* getAsString(bool &del, int foff, ExceptionSink* xsink) const;
DLLEXPORT virtual AbstractQoreNode* realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
DLLEXPORT virtual const char* getTypeName() const;
DLLEXPORT QoreHashNode* hashRefSelf() const;
DLLEXPORT const char* getFirstKey() const;
DLLEXPORT const char* getLastKey() const;
DLLEXPORT AbstractQoreNode* getKeyValueExistence(const char* key, bool &exists);
DLLEXPORT const AbstractQoreNode* getKeyValueExistence(const char* key, bool &exists) const;
DLLEXPORT AbstractQoreNode* getKeyValueExistence(const QoreString* key, bool &exists, ExceptionSink* xsink);
DLLEXPORT const AbstractQoreNode* getKeyValueExistence(const QoreString* key, bool &exists, ExceptionSink* xsink) const;
DLLEXPORT AbstractQoreNode* getKeyValue(const QoreString* key, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* getKeyValue(const QoreString& key, ExceptionSink* xsink);
DLLEXPORT const AbstractQoreNode* getKeyValue(const QoreString* key, ExceptionSink* xsink) const;
DLLEXPORT AbstractQoreNode* getKeyValue(const char* key);
DLLEXPORT const AbstractQoreNode* getKeyValue(const char* key) const;
DLLEXPORT int64 getKeyAsBigInt(const char* key, bool &found) const;
DLLEXPORT bool getKeyAsBool(const char* key, bool &found) const;
DLLEXPORT QoreHashNode* copy() const;
DLLEXPORT AbstractQoreNode** getKeyValuePtr(const QoreString* key, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode** getKeyValuePtr(const char* key);
DLLEXPORT AbstractQoreNode** getExistingValuePtr(const QoreString* key, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode** getExistingValuePtr(const char* key);
DLLEXPORT void merge(const QoreHashNode* h, ExceptionSink* xsink);
DLLEXPORT void setKeyValue(const QoreString* key, AbstractQoreNode* value, ExceptionSink* xsink);
DLLEXPORT void setKeyValue(const QoreString& key, AbstractQoreNode* value, ExceptionSink* xsink);
DLLEXPORT void setKeyValue(const char* key, AbstractQoreNode* value, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* swapKeyValue(const QoreString* key, AbstractQoreNode* value, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* swapKeyValue(const char* key, AbstractQoreNode* value);
DLLEXPORT AbstractQoreNode* swapKeyValue(const char* key, AbstractQoreNode* value, ExceptionSink* xsink);
DLLEXPORT void deleteKey(const QoreString* key, ExceptionSink* xsink);
DLLEXPORT void deleteKey(const char* key, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* takeKeyValue(const QoreString* key, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* takeKeyValue(const char* key);
DLLEXPORT QoreListNode* getKeys() const;
DLLEXPORT bool compareSoft(const QoreHashNode* h, ExceptionSink* xsink) const;
DLLEXPORT bool compareHard(const QoreHashNode* h, ExceptionSink* xsink) const;
DLLEXPORT qore_size_t size() const;
DLLEXPORT bool empty() const;
DLLEXPORT bool existsKey(const char* key) const;
DLLEXPORT bool existsKeyValue(const char* key) const;
DLLEXPORT void removeKey(const QoreString* key, ExceptionSink* xsink);
DLLEXPORT void removeKey(const char* key, ExceptionSink* xsink);
DLLLOCAL static const char* getStaticTypeName() {
return "hash";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_HASH;
}
DLLLOCAL virtual AbstractQoreNode* parseInit(LocalVar* oflag, int pflag, int& lvids, const QoreTypeInfo*& typeInfo);
DLLLOCAL QoreHashNode(bool ne);
DLLLOCAL void clear(ExceptionSink* xsink);
DLLLOCAL void clearNeedsEval();
DLLLOCAL void setNeedsEval();
DLLLOCAL AbstractQoreNode* evalKeyValue(const QoreString* key, ExceptionSink* xsink) const;
// returns a new hash consisting of just the members of value_list
DLLLOCAL QoreHashNode* getSlice(const QoreListNode* value_list, ExceptionSink* xsink) const;
// "key" is always passed in the default character encoding
DLLLOCAL AbstractQoreNode* getReferencedKeyValue(const char* key) const;
// "key" is always passed in the default character encoding
DLLLOCAL AbstractQoreNode* getReferencedKeyValue(const char* key, bool& exists) const;
DLLLOCAL static void doDuplicateKeyWarning(const char* key);
};
#include <qore/ReferenceHolder.h>
typedef ReferenceHolder<QoreHashNode> QoreHashNodeHolder;
class HashIterator {
friend class HashAssignmentHelper;
protected:
QoreHashNode* h;
HashMember *ptr;
DLLLOCAL HashIterator(const HashIterator&);
DLLLOCAL HashIterator& operator=(const HashIterator&);
DLLLOCAL void* operator new(size_t);
public:
DLLEXPORT HashIterator(QoreHashNode* h);
DLLEXPORT HashIterator(QoreHashNode& h);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT const char* getKey() const;
DLLEXPORT QoreString* getKeyString() const;
DLLEXPORT AbstractQoreNode* getValue() const;
DLLEXPORT AbstractQoreNode* takeValueAndDelete();
DLLEXPORT void deleteKey(ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode** getValuePtr() const;
DLLEXPORT AbstractQoreNode* getReferencedValue() const;
DLLEXPORT bool first() const;
DLLEXPORT bool last() const;
DLLEXPORT bool empty() const;
DLLEXPORT bool valid() const;
};
class ReverseHashIterator : public HashIterator {
public:
DLLEXPORT ReverseHashIterator(QoreHashNode* h);
DLLEXPORT ReverseHashIterator(QoreHashNode& h);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT bool first() const;
DLLEXPORT bool last() const;
};
class ConstHashIterator {
protected:
const QoreHashNode* h;
HashMember *ptr;
DLLLOCAL ConstHashIterator(const HashIterator&);
DLLLOCAL ConstHashIterator& operator=(const HashIterator&);
DLLLOCAL ConstHashIterator(const QoreHashNode* n_h, HashMember* n_ptr);
public:
DLLEXPORT ConstHashIterator(const QoreHashNode* h);
DLLEXPORT ConstHashIterator(const QoreHashNode& h);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT const char* getKey() const;
DLLEXPORT QoreString* getKeyString() const;
DLLEXPORT const AbstractQoreNode* getValue() const;
DLLEXPORT AbstractQoreNode* getReferencedValue() const;
DLLEXPORT bool first() const;
DLLEXPORT bool last() const;
DLLEXPORT bool empty() const;
DLLEXPORT bool valid() const;
DLLEXPORT void reset();
};
class ReverseConstHashIterator : public ConstHashIterator {
public:
DLLEXPORT ReverseConstHashIterator(const QoreHashNode* h);
DLLEXPORT ReverseConstHashIterator(const QoreHashNode& h);
DLLEXPORT bool next();
DLLEXPORT bool prev();
DLLEXPORT bool first() const;
DLLEXPORT bool last() const;
};
class HashAssignmentHelper {
private:
DLLLOCAL HashAssignmentHelper(const HashAssignmentHelper&);
DLLLOCAL HashAssignmentHelper& operator=(const HashAssignmentHelper&);
DLLLOCAL void* operator new(size_t);
protected:
class hash_assignment_priv *priv;
public:
DLLLOCAL HashAssignmentHelper(QoreHashNode& n_h, const char* key, bool must_already_exist = false);
DLLLOCAL HashAssignmentHelper(QoreHashNode& n_h, const std::string& key, bool must_already_exist = false);
DLLLOCAL HashAssignmentHelper(ExceptionSink* xsink, QoreHashNode& n_h, const QoreString& key, bool must_already_exist = false);
DLLLOCAL HashAssignmentHelper(ExceptionSink* xsink, QoreHashNode& n_h, const QoreString* key, bool must_already_exist = false);
DLLLOCAL HashAssignmentHelper(HashIterator &hi);
DLLLOCAL ~HashAssignmentHelper();
DLLLOCAL operator bool() const;
DLLLOCAL void assign(AbstractQoreNode* v, ExceptionSink* xsink);
DLLLOCAL AbstractQoreNode* swap(AbstractQoreNode* v, ExceptionSink* xsink);
DLLLOCAL AbstractQoreNode* operator*() const;
};
#endif // _QORE_HASH_H