Added new hash table implementation.
authormike <mike>
Fri, 27 Apr 2001 00:00:59 +0000 (00:00 +0000)
committermike <mike>
Fri, 27 Apr 2001 00:00:59 +0000 (00:00 +0000)
Cleaned up some more docs.

13 files changed:
doc/TODO
mak/docxx.mak
src/Pegasus/Common/CIMClass.h
src/Pegasus/Common/CIMInstance.h
src/Pegasus/Common/CIMMethod.h
src/Pegasus/Common/CIMProperty.h
src/Pegasus/Common/CIMReference.cpp
src/Pegasus/Common/HashTable.cpp [new file with mode: 0644]
src/Pegasus/Common/HashTable.h [new file with mode: 0644]
src/Pegasus/Common/Makefile
src/Pegasus/Repository/CIMRepository.cpp
src/Pegasus/Repository/CIMRepository.h
src/utils/jd/README

index a2b51a75b0d19ef7b28a9a217aa296003470f2c2..2335f7655bdfa97f58fd8db5d21dc13e2c015932 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,6 +1,6 @@
 
-                               TO-DO List
-                               ==========
+Topical To-Do List
+==================
 
 -   Instances:
 
 
     -   Run CIM/XML test suite.
 
+-   Server
+
+    -   Use Service class in cimserver
+
+    -   Implement Service class on Unix (daemonization from Comer book).
index 90c799a50c78ea3d98a6f651738262ceb77f1327..2b03be5bec81f1b558a265d82ec6a03a5a2ff151 100644 (file)
@@ -1,3 +1,9 @@
 
+.PHONY: docxx
+
+DOC_ROOT = $(ROOT)/doc/reference
+DOC_DIR = $(DOC_ROOT)/$(DIR)
+
 docxx:
-       docxx -d ./doc -H *.h
+       $(MKDIRHIER) $(DOC_DIR)
+       docxx -d $(DOC_DIR) -H *.h
index c99f1948a863ced5d365d8af9e1891bd1c537e44..67c25f05062dd0f2a8661c611d1749521011fbad 100644 (file)
@@ -183,10 +183,6 @@ public:
        return _rep->findQualifier(name);
     }
 
-    /** CIMMethod FindQualifier - ATTN:
-       @param name of the qualifier to be found
-       @return ATTN: Define this
-    */
     Uint32 findQualifier(const String& name) const
     {
        _checkRep();
@@ -257,7 +253,6 @@ public:
        return _rep->findProperty(name);
     }
 
-    /// CIMMethod findProperty
     Uint32 findProperty(const String& name) const
     {
        _checkRep();
@@ -318,7 +313,6 @@ public:
        return _rep->findMethod(name);
     }
 
-    /// CIMMethod findMethod - ATTN:
     Uint32 findMethod(const String& name) const
     {
        _checkRep();
index 0a80fe53bf56b89a72babe4524384e1fa7a537c6..92f7b47d54452cc8746c3382e5693ae907941ef4 100644 (file)
@@ -131,12 +131,6 @@ public:
        return _rep->findQualifier(name);
     }
 
-    /**        findQualifier - Searches the instance for the qualifier object
-        defined by the input parameter.
-       @param String defining the qualifier to be found
-       @return - Index of the qualifier to be used in subsequent 
-       operations or -1 if the qualifier is not found. 
-    */ 
     Uint32 findQualifier(const String& name) const
     {
        _checkRep();
@@ -219,13 +213,6 @@ public:
        return _rep->findProperty(name);
     }
 
-    /**        findProperty - Searches the property objects installed in the 
-       CIMInstance for property objects with the name defined by the
-       input
-       @param String with the name of the property object to be found
-       @return Index in the CIM Instance to the property object if found or 
-       -1 if no property object found with the name defined by the input. 
-    */  
     Uint32 findProperty(const String& name) const
     {
        _checkRep();
index d047e70c059bdc494dbe8b9d503b07bc9315b3be..b6f0393e295e48007b3378146995cb2299dd8d92 100644 (file)
 //
 //%/////////////////////////////////////////////////////////////////////////////
 
-/*
- CIMMethod.h - This header file defines the method class.
-*/
-
 #ifndef Pegasus_Method_h
 #define Pegasus_Method_h
 
 
 PEGASUS_NAMESPACE_BEGIN
 
-
 class CIMConstMethod;
 
 /** Class CIMMethod - This class defines the operations associated with
-manipulation of the Pegasus implementation of the CIM CIMMethod.  Within this
-class, methods are provides for creation, deletion, and manipulation of method
-declarations.
+    manipulation of the Pegasus implementation of the CIM CIMMethod. Within 
+    this class, methods are provides for creation, deletion, and manipulation 
+    of method declarations.
 
+    // ATTN: remove the classOrigin and propagated parameters.
 */
-
 class PEGASUS_COMMON_LINKAGE CIMMethod
 {
 public:
-    /// Creates and instantiates a CIM method.
+
+    /** Creates and instantiates a CIM method. */
     CIMMethod() : _rep(0)
     {
 
     }
+
     /** Creates and instantiates a CIM method from another method instance
-    @return pointer to the new method instance
+       @return pointer to the new method instance
     */
     CIMMethod(const CIMMethod& x)
     {
        Inc(_rep = x._rep);
     }
-    ///
+
+    /** Assignment operator */
     CIMMethod& operator=(const CIMMethod& x)
     {
        if (x._rep != _rep)
@@ -73,14 +71,12 @@ public:
        return *this;
     }
 
-    // ATTN: remove the classOrigin and propagated parameters.
-
     /**         Creates a CIM method with the specified name, type, and classOrigin
-    @param name for the method
-    @param type ATTN
-    @param classOrigin
-    @param propagated
-    @return  Throws IllegalName if name argument not legal CIM identifier.
+       @param name for the method
+       @param type ATTN
+       @param classOrigin
+       @param propagated
+       @return  Throws IllegalName if name argument not legal CIM identifier.
     */
     CIMMethod(
        const String& name,
@@ -91,13 +87,14 @@ public:
        _rep = new CIMMethodRep(name, type, classOrigin, propagated);
     }
 
-    /// CIMMethod desctructor
+    /** Desctructor. */
     ~CIMMethod()
     {
        Dec(_rep);
     }
+
     /** CIMMethod getName - Gets the name of the method
-    @return String with the name of the method
+       @return String with the name of the method
     */
     const String& getName() const
     {
@@ -106,65 +103,70 @@ public:
     }
 
     /** CIMMethod setName - Set the method name
-    @parm name ATTN (make reference to name defintion here)
-    @return Throws IllegalName if name argument not legal CIM identifier.
+       @param name
+       @exception IllegalName if name argument not legal CIM identifier.
     */
     void setName(const String& name)
     {
        _checkRep();
        _rep->setName(name);
     }
+
     /** CIMMethod getType - gets the method type
-    @return The CIM method type for this method.
+       @return The CIM method type for this method.
     */
-
     CIMType getType() const
     {
        _checkRep();
        return _rep->getType();
     }
+
     /** CIMMethod setType - Sets the method type to the specified CIM method
-    type as defined in CIMType /Ref{TYPE}
+       type as defined in CIMType /Ref{TYPE}
     */
     void setType(CIMType type)
     {
        _checkRep();
        _rep->setType(type);
     }
+
     /** CIMMethod getClassOrigin - Returns the class in which this method
-     was defined.
-    @return ATTN:
+       was defined.  
+       @return ATTN:
     */
     const String& getClassOrigin() const
     {
        _checkRep();
        return _rep->getClassOrigin();
     }
-    /** CIMMethod setClassOrigin - ATTN:
-    */
+
+    /** CIMMethod setClassOrigin - ATTN: */
     void setClassOrigin(const String& classOrigin)
     {
        _checkRep();
        _rep->setClassOrigin(classOrigin);
     }
-    /// method getPropagated - ATTN:
+
+    /** method getPropagated - ATTN: */
     Boolean getPropagated() const
     {
        _checkRep();
        return _rep->getPropagated();
     }
-    /// method setPropagated - ATTN:
+
+    /** method setPropagated - ATTN: */
     void setPropagated(Boolean propagated)
     {
        _checkRep();
        _rep->setPropagated(propagated);
     }
+
     /** CIMMethod addQualifier -
-    @parm CIMQualifier to add
-    @param CIMQualifier to be added
-    @return Throws AlreadyExists excetpion if the qualifier already exists in
-    the method
-    @exception         AlreadyExists exception of CIMQualifier already exists.
+       @parm CIMQualifier to add
+       @param CIMQualifier to be added
+       @return Throws AlreadyExists excetpion if the qualifier already exists 
+       in the method
+       @exception AlreadyExists exception
     */
     CIMMethod& addQualifier(const CIMQualifier& x)
     {
@@ -172,39 +174,30 @@ public:
        _rep->addQualifier(x);
        return *this;
     }
-    /** CIMMethod findQualifier - Finds the CIMQualifier named by the input string.
-    @param String defining the name of the parameter to be found
-    @return Index to the parameter found or -1 if not found
-    The -1 must be converted to a Unit32 as follows:
-    <PRE>
-       Uint32 pos = myClass.findProperty("name");
-       if (pos == Uint32(-1))
-       {
-           // Not found!
-       }
-    </PRE>
+
+    /** CIMMethod findQualifier - returns the position of the qualifier with
+       the given name.
+       @param name - name of qualifier to be found.
+       @return index of the parameter if found; otherwise Uint32(-1).
     */
     Uint32 findQualifier(const String& name)
     {
        _checkRep();
        return _rep->findQualifier(name);
     }
-    /** CIMMethod findQualifier - Find the qualifier with the name defined on
-    input
-    @param String with the name of the parameter to be found.
-    @return - index to the qualifier found or -1 if no qualifier found.
-    */
+
     Uint32 findQualifier(const String& name) const
     {
        _checkRep();
        return _rep->findQualifier(name);
     }
-    /** CIMMethod getQualifier - Gets the CIMQualifier defined by the index input
-    as a parameter.
-    @param Index of the qualifier requested.
-    @return CIMQualifier object or exception
-    @exception OutOfBounds exception if the index is outside the range of
-    parameters available from the CIMMethod.
+
+    /** CIMMethod getQualifier - Gets the CIMQualifier defined by the index 
+       input as a parameter.
+       @param Index of the qualifier requested.
+       @return CIMQualifier object or exception
+       @exception OutOfBounds exception if the index is outside the range of
+       parameters available from the CIMMethod.
     */
     CIMQualifier getQualifier(Uint32 pos)
     {
@@ -217,18 +210,19 @@ public:
        _checkRep();
        return _rep->getQualifier(pos);
     }
-    /** CIMMethod getQualifierCount - Returns count of the number of Qualifiers
-    attached to the CIMMethod
-    @return integer representing number of Qualifiers.
+
+    /** CIMMethod getQualifierCount - Returns the number of Qualifiers attached
+       to this method.
+       @return integer representing number of Qualifiers.
     */
     Uint32 getQualifierCount() const
     {
        _checkRep();
        return _rep->getQualifierCount();
     }
-    /** CIMMethod addParameter - Adds the parameter defined by the input to the
-    CIMMethod
-    Param - ATTN:
+
+    /** CIMMethod addParameter - Adds the parameter defined by the input 
+       to the CIMMethod
     */
     CIMMethod& addParameter(const CIMParameter& x)
     {
@@ -236,25 +230,25 @@ public:
        _rep->addParameter(x);
        return *this;
     }
-    /// CIMMethod findParameter - ATTN:
+
+    /** CIMMethod findParameter - Finds the parameter whose name is given
+       by the name parameter.
+       @param name - name of parameter to be found.
+       @return index of the parameter if found; otherwise Uint32(-1).
+    */
     Uint32 findParameter(const String& name)
     {
        _checkRep();
        return _rep->findParameter(name);
     }
 
-    /** CIMMethod findParameter - Finds the parameter defined by the name input
-    and returns an index to the CIMParameter
-    @param String defining the parameter to be found
-    @return index to the parameter if found.  Returns -1 if parameter not
-    found
-    */
-     Uint32 findParameter(const String& name) const
+    Uint32 findParameter(const String& name) const
     {
        _checkRep();
        return _rep->findParameter(name);
     }
-    /// CIMMethod getParameter - ATTN:
+
+    /** CIMMethod getParameter - ATTN: */
     CIMParameter getParameter(Uint32 pos)
     {
        _checkRep();
@@ -262,11 +256,11 @@ public:
     }
 
     /** CIMMethod getParameter - Gets the parameter defined by the index
-    input as a parameter.
-    @param index for the parameter to be returned.
-    @return CIMParameter requested.
-    @Exception OutOfBounds exception is thrown if the index is outside the
-    range of available parameters
+       input as a parameter.
+       @param index for the parameter to be returned.
+       @return CIMParameter requested.
+       @Exception OutOfBounds exception is thrown if the index is outside the
+       range of available parameters
     */
     CIMConstParameter getParameter(Uint32 pos) const
     {
@@ -274,16 +268,17 @@ public:
        return _rep->getParameter(pos);
     }
 
-    /** CIMMethod getParameterCount - Gets the count of the numbeer of Parameters
-    attached to the CIMMethod.
-    @retrun - count of the number of parameters attached to the CIMMethod.
+    /** CIMMethod getParameterCount - Gets the count of the numbeer of 
+       Parameters attached to the CIMMethod.
+       @retrun - count of the number of parameters attached to the CIMMethod.
     */
     Uint32 getParameterCount() const
     {
        _checkRep();
        return _rep->getParameterCount();
     }
-    /// method resolve - ATTN:
+
+    /** method resolve - ATTN: */
     void resolve(
        DeclContext* declContext,
        const String& nameSpace,
@@ -292,7 +287,8 @@ public:
        _checkRep();
        _rep->resolve(declContext, nameSpace, method);
     }
-    /// CIMMethod resolve
+
+    /** CIMMethod resolve */
     void resolve(
        DeclContext* declContext,
        const String& nameSpace)
@@ -300,23 +296,33 @@ public:
        _checkRep();
        _rep->resolve(declContext, nameSpace);
     }
-    /// operator
-    operator int() const { return _rep != 0; }
-    /// method toXML - ATTN:
+
+    /** Returns zero if CIMMethod refers to a null pointer */
+    operator int() const 
+    { 
+       return _rep != 0; 
+    }
+
+    /** method toXML - placing XML encoding of this object into out arguemnt. */
     void toXml(Array<Sint8>& out) const
     {
        _checkRep();
        _rep->toXml(out);
     }
-    /// method print - ATTN:
+
+    /** method print - prints this method (in CIM encoded form). */
     void print(std::ostream &o=std::cout) const
     {
        _checkRep();
        _rep->print(o);
     }
-    /// CIMMethod identical - ATTN
+
+    /** CIMMethod identical - Returns true if this method is identical to the
+       one given by the argument x.
+    */
     Boolean identical(const CIMConstMethod& x) const;
-    /// CIMMethod clone - ATTN
+
+    /** CIMMethod clone - makes a distinct replica of this method */
     CIMMethod clone() const
     {
        return CIMMethod(_rep->clone());
@@ -341,12 +347,6 @@ private:
     friend class CIMClassRep;
 };
 
-////////////////////////////////////////////////////////////////////////////////
-//
-// CIMConstMethod
-//
-////////////////////////////////////////////////////////////////////////////////
-
 class PEGASUS_COMMON_LINKAGE CIMConstMethod
 {
 public:
index a9c99425519d63fa16b9b7649bed4ba4877a1671..6abbbfbeb0347f491eef4d041ea734735dbf288a 100644 (file)
@@ -181,7 +181,6 @@ public:
        return _rep->findQualifier(name);
     }
 
-    /// CIMMethod findQualifier - ATTN
     Uint32 findQualifier(const String& name) const
     {
        _checkRep();
index 4e170df2cde3ad84d13fb479810be7b547536ae8..672b888bfb394c5e29e27d8b0f52fdca3d9bf8e1 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <cctype>
 #include <cstring>
+#include "HashTable.h"
 #include "CIMReference.h"
 #include "Indentor.h"
 #include "CIMName.h"
@@ -614,16 +615,6 @@ const char* KeyBinding::typeToString(Type type)
     return "unknown";
 }
 
-static inline Uint32 _Hash(const String& str)
-{
-    Uint32 h = 0;
-
-    for (Uint32 i = 0, n = str.getLength(); i < n; i++)
-       h = 5 * h + str[i];
-
-    return h;
-}
-
 Uint32 CIMReference::makeHashCode() const
 {
     CIMReference ref = *this;
@@ -633,7 +624,7 @@ Uint32 CIMReference::makeHashCode() const
     for (Uint32 i = 0, n = ref._keyBindings.getSize(); i < n; i++)
        ref._keyBindings[i]._name.toLower();
 
-    return _Hash(ref.toString());
+    return Hash(ref.toString());
 }
 
 PEGASUS_NAMESPACE_END
diff --git a/src/Pegasus/Common/HashTable.cpp b/src/Pegasus/Common/HashTable.cpp
new file mode 100644 (file)
index 0000000..2efe529
--- /dev/null
@@ -0,0 +1,231 @@
+//%/////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+// Author: Mike Brasher (mbrasher@bmc.com)
+//
+// Modified By:
+//
+//%/////////////////////////////////////////////////////////////////////////////
+
+#include <cstring>
+#include "HashTable.h"
+
+PEGASUS_NAMESPACE_BEGIN
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Hash()
+//
+////////////////////////////////////////////////////////////////////////////////
+
+Uint32 Hash(const String& str)
+{
+    Uint32 h = 0;
+
+    for (Uint32 i = 0, n = str.getLength(); i < n; i++)
+        h = 5 * h + str[i];
+
+    return h;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// HashTableBase::BucketBase
+//
+////////////////////////////////////////////////////////////////////////////////
+
+BucketBase::~BucketBase()
+{
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// HashTableIteratorBase
+//
+////////////////////////////////////////////////////////////////////////////////
+
+HashTableIteratorBase HashTableIteratorBase::operator++(int)
+{
+    HashTableIteratorBase tmp = *this;
+    operator++();
+    return tmp;
+}
+
+HashTableIteratorBase& HashTableIteratorBase::operator++()
+{
+    // At the end?
+
+    if (!_bucket)
+        return *this;
+
+    // More buckets this chain?
+
+    if ((_bucket = _bucket->next))
+        return *this;
+
+    // Find the next non-empty chain:
+
+    _bucket = 0;
+
+    while (_first != _last)
+    {
+        if (*_first)
+       {
+           _bucket = *_first++;
+           break;
+       }
+
+       _first++;
+    }
+
+    return *this;
+}
+
+HashTableIteratorBase::HashTableIteratorBase(
+    BucketBase** first, 
+    BucketBase** last) : _first(first), _last(last)
+{
+    while (_first != last)
+    {
+        if (*_first)
+       {
+           _bucket = *_first++;
+           break;
+       }
+
+       _first++;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// HashTableBase
+//
+////////////////////////////////////////////////////////////////////////////////
+
+HashTableBase::HashTableBase(Uint32 numChains) : _size(0), _numChains(numChains)
+{
+    if (numChains < 8)
+       numChains = 8;
+
+    _chains = new BucketBase*[_numChains];
+    memset(_chains, 0, sizeof(BucketBase*) * _numChains);
+}
+
+HashTableBase::~HashTableBase()
+{
+    clear();
+}
+
+void HashTableBase::clear()
+{
+    for (Uint32 i = 0; i < _numChains; i++)
+    {
+       for (BucketBase* bucket = _chains[i]; bucket; )
+       {
+           BucketBase* next = bucket->next;
+           delete bucket;
+           bucket = next;
+       }
+    }
+
+    _size = 0;
+    memset(_chains, 0, sizeof(BucketBase*) * _numChains);
+}
+
+Boolean HashTableBase::insert(
+    Uint32 hashCode, 
+    BucketBase* bucket, 
+    const void* key)
+{
+    // Check for duplicate entry with same key:
+
+    Uint32 i = hashCode % _numChains;
+    BucketBase* last = 0;
+
+    for (BucketBase* bucket = _chains[i]; bucket; bucket = bucket->next)
+    {
+       if (bucket->equal(key))
+       {
+           delete bucket;
+           return false;
+       }
+
+       last = bucket;
+    }
+
+    // Insert bucket:
+
+    bucket->next = 0;
+
+    if (last)
+       last->next = bucket;
+    else
+       _chains[i] = bucket;
+
+    _size++;
+    return true;
+}
+
+const BucketBase* HashTableBase::lookup(
+    Uint32 hashCode, 
+    const void* key)
+{
+    Uint32 i = hashCode % _numChains;
+
+    for (BucketBase* bucket = _chains[i]; bucket; bucket = bucket->next)
+    {
+       if (bucket->equal(key))
+           return bucket;
+    }
+
+    // Not found!
+    return 0;
+}
+
+Boolean HashTableBase::remove(Uint32 hashCode, const void* key)
+{
+    for (Uint32 i = 0; i < _numChains; i++)
+    {
+       BucketBase* prev = 0;
+
+       for (BucketBase* bucket = _chains[i]; bucket; bucket = bucket->next)
+       {
+           if (bucket->equal(key))
+           {
+               if (prev)
+                   prev->next = bucket->next;
+               else
+                   _chains[i] = bucket->next;
+
+               delete bucket;
+               _size--;
+               return true;
+           }
+           prev = bucket;
+       }
+    }
+
+    return false;
+}
+
+PEGASUS_NAMESPACE_END
diff --git a/src/Pegasus/Common/HashTable.h b/src/Pegasus/Common/HashTable.h
new file mode 100644 (file)
index 0000000..33f5cf3
--- /dev/null
@@ -0,0 +1,280 @@
+//%/////////////////////////////////////////////////////////////////////////////
+//
+// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+//==============================================================================
+//
+// Author: Mike Brasher (mbrasher@bmc.com)
+//
+// Modified By:
+//
+//%/////////////////////////////////////////////////////////////////////////////
+
+#ifndef Pegasus_HashTable_h
+#define Pegasus_HashTable_h
+
+#include <Pegasus/Common/Config.h>
+#include <Pegasus/Common/String.h>
+
+PEGASUS_NAMESPACE_BEGIN
+
+PEGASUS_COMMON_LINKAGE inline Uint32 Hash(const String& str);
+
+/** Representation for a bucket. The HashTable class derives from this
+    bucket to append a key and value. This base class just defines
+    the pointer to the next bucket in the chain.
+*/
+class PEGASUS_COMMON_LINKAGE BucketBase
+{
+public:
+
+    /** Virtual destructor to ensure destruction of derived class 
+       elements.
+    */
+    virtual ~BucketBase();
+
+    /** returns true if the key pointed to by the key argument is equal
+       to the internal key of this bucket. This method must be overridden
+       by the derived class.
+    */
+    virtual Boolean equal(const void* key) const = 0;
+
+    BucketBase* next;
+};
+
+class HashTableBase;
+
+/** This class implements a simple hash table forward iterator. */
+class PEGASUS_COMMON_LINKAGE HashTableIteratorBase
+{
+public:
+    
+    HashTableIteratorBase() : _first(0), _last(0), _bucket(0) { }
+
+    operator Boolean() const { return _bucket != 0; }
+
+    HashTableIteratorBase operator++(int);
+
+    HashTableIteratorBase& operator++();
+
+    HashTableIteratorBase(BucketBase** first, BucketBase** last);
+
+protected:
+
+    BucketBase** _first;
+    BucketBase** _last;
+    BucketBase* _bucket;
+    friend HashTableBase;
+};
+
+/** The HashTableBase class is the base class which HashTable derives from. 
+
+    This code is primarily an internal class used to implement the HashTable.
+    But there may be occasions to use it directly.
+
+    HashTableBase parcels out much of the large code so that that code is not 
+    instantiated by the HashTable template class many times. This scheme helps 
+    reduce code bloat caused by templates. The HashTable template class below
+    acts as kind of a wrapper around this class.
+
+    HashTableBase is implemented as an array of pointers to chains of hash
+    buckets. The table initially allocates some number of chains (which can
+    be controlled by the constructor) and then may increase the number of
+    chains later (resulting in a reorganization of the hash table).
+
+    ATTN: reorganization not supported yet.
+*/
+class PEGASUS_COMMON_LINKAGE HashTableBase
+{
+public:
+
+    /** This constructor allocates an array of pointers to chains of buckets,
+       which of course are all empty at this time. The numChains argument
+       If the numChains argument is less than eight, then eight chains will
+       be created.
+       @param numChains - specifies the initial number of chains.
+    */
+    HashTableBase(Uint32 numChains);
+
+    /** Destructor. */
+    ~HashTableBase();
+
+    /** Returns the size of this hash table (the number of entries). */
+    Uint32 getSize() const { return _size; }
+
+    /** Clears the contents of this hash table. After this is called, the
+       getSize() method returns zero.
+    */
+    void clear();
+
+    /** Inserts new key-value pair into hash table. Deletes the bucket on
+       failure so caller need not.
+       @param hashCode - hash code generated by caller's hash function.
+       @param bucket - bucket to be inserted.
+       @param key - pointer to key.
+       @return true if insertion successful; false if duplicate key.
+    */
+    Boolean insert(Uint32 hashCode, BucketBase* bucket, const void* key);
+
+    /** Finds the bucket with the given key. This method uses the
+       BucketBase::equal() method to compare keys.
+       @param hashCode - hash code generated by caller's hash function.
+       @param key - void pointer to key.
+       @return pointer to bucket with that key or zero otherwise.
+    */
+    const BucketBase* lookup(Uint32 hashCode, const void* key);
+
+    /** Removes the bucket with the given key. This method uses the
+       BucketBase::equal() method to compare keys.
+       @param hashCode - hash code generated by caller's hash function.
+       @param key - void pointer to key.
+       @return true if entry found and removed and false otherwise.
+    */
+    Boolean remove(Uint32 hashCode, const void* key);
+
+protected:
+
+    Uint32 _size;
+    Uint32 _numChains;
+    BucketBase** _chains;
+};
+
+/** The Bucket class is used to implement the HashTable class.
+*/
+template<class K, class V>
+class Bucket : public BucketBase
+{
+public:
+
+    Bucket(const K& key, const V& value) : _key(key), _value(value) { }
+
+    virtual ~Bucket();
+
+    virtual Boolean equal(const void* key) const;
+
+    K& getKey() { return _key; }
+
+    V& getValue() { return _value; }
+
+private:
+
+    K _key;
+    V _value;
+};
+
+template<class K, class V>
+Boolean Bucket<K,V>::equal(const void* key) const
+{
+    return *((K*)key) == _key;
+}
+
+template<class K, class V>
+Bucket<K,V>::~Bucket()
+{
+
+}
+
+/** Iterator for HashTable class. */
+template<class K, class V>
+class HashTableIterator : public HashTableIteratorBase
+{
+public:
+
+    HashTableIterator() 
+       : HashTableIteratorBase() { }
+
+    HashTableIterator(BucketBase** first, BucketBase** last)
+       : HashTableIteratorBase(first, last) { }
+
+    const K& key() const { return ((Bucket<K,V>*)_bucket)->getKey(); }
+
+    const V& value() const { return ((Bucket<K,V>*)_bucket)->getValue(); }
+};
+
+/** HashTable provides a simple hash table implementation which associates
+    key-value pairs.
+*/
+template<class K, class V>
+class HashTable : public HashTableBase
+{
+public:
+
+    typedef HashTableIterator<K,V> Iterator;
+
+    /** By default, we create this many chains initially */
+    enum { DEFAULT_NUM_CHAINS = 32 };
+
+    /** Constructor.
+       @param numChains - number of chains to create.
+    */
+    HashTable(Uint32 numChains = DEFAULT_NUM_CHAINS) 
+       : HashTableBase(numChains)
+    {
+    }
+
+    /** Inserts new key-value pair into hash table.
+       @param key - key component.
+       @param value - value component.
+       @return true on success; false if duplicate key.
+    */
+    Boolean insert(const K& key, const V& value)
+    {
+       return HashTableBase::insert(
+           Hash(key), new Bucket<K,V>(key, value), &key);
+    }
+
+    /** Looks up the entry with the given key.
+       @param key - key of entry to be located.
+       @param value - output value.
+       @return true if found; false otherwise.
+    */
+    Boolean lookup(const K& key, V& value);
+
+    /** Removes the entry with the given key.
+       @param key - key of entry to be removed.
+       @return true on success; false otherwise.
+    */
+    Boolean remove(const K& key)
+    {
+       return HashTableBase::remove(Hash(key), &key);
+    }
+
+    /** Obtains an iterator for this object. */
+    Iterator start() const 
+    {
+       return Iterator(_chains, _chains + _numChains);
+    }
+};
+
+template<class K, class V>
+inline Boolean HashTable<K,V>::lookup(const K& key, V& value)
+{
+    Bucket<K,V>* bucket = (Bucket<K,V>*)HashTableBase::lookup(Hash(key), &key);
+
+    if (bucket)
+    {
+       value = bucket->getValue();
+       return true;
+    }
+
+    return false;
+}
+
+PEGASUS_NAMESPACE_END
+
+#endif /* Pegasus_HashTable_h */
index c8a61ab8e7ad6c510088c5b5db95df7a344ca403..eb1fe9bfd34670e216d7e3173beb0e217d76b88d 100644 (file)
@@ -9,6 +9,7 @@ LOCAL_DEFINES = -DPEGASUS_COMMON_INTERNAL
 LIBRARY = pegcommon
 
 SOURCES = \
+    HashTable.cpp \
     Service.cpp \
     OptionManager.cpp \
     CGIQueryString.cpp \
index 16e5e55bdb039dc394298afb78b33140c357a0d0..f15a0e4c8c5c89c6890293f0e7c1beb31b61f315 100644 (file)
@@ -650,6 +650,8 @@ void CIMRepository::createInstance(
     CIMReference instanceName = newInstance.getInstanceName(cimClass);
     Uint32 index;
 
+    // ATTN: Should throw "object already exists" exception!
+
     if (!InstanceIndexFile::insert(indexFilePath, instanceName, index))
        throw CIMException(CIMException::FAILED);
 
@@ -1072,6 +1074,8 @@ void CIMRepository::deleteNameSpace(const String& nameSpace)
 
 // Recall flavor defaults: TOSUBCLASS | OVERRIDABLE
 
+#if 0
+
 void CIMRepository::_createMetaQualifiers(const String& nameSpace)
 {
     // CIMQualifier CimType : string = null, 
@@ -1463,4 +1467,6 @@ void CIMRepository::_createMetaQualifiers(const String& nameSpace)
        CIMScope::PROPERTY));
 }
 
+#endif
+
 PEGASUS_NAMESPACE_END
index 8f84442f8e27a84fdf48c3d3170d3b5a05cb1e65..42d952f44c536a91805401d4224abb89061e35ea 100644 (file)
@@ -252,7 +252,9 @@ private:
        advent of the MOF compiler/loader. The XML Schema had no qualifiers
        included in it so the XML loader needed a way to create them.
     */
+#if 0
     void _createMetaQualifiers(const String& nameSpace);
+#endif
 
     String _root;
     RepositoryDeclContext* _context;
index 9563e6c0dc6397bcf7c955c18835b5148de2e2d4..a3120300eff41832824b362da789ffafe6e398b1 100644 (file)
@@ -2,7 +2,7 @@
 OVERVIEW
 ========
 
-This utility emulates on NT the JDPATH behavior of the Unix C-Shell. Its use
+This utility emulates on NT the CDPATH behavior of the Unix C-Shell. Its use
 is trivial:
 
     1. Copy jdath.exe and jd.bat to a directory on your path.