uima-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r503249 [4/6] - /incubator/uima/uimacpp/trunk/src/cas/uima/
Date Sat, 03 Feb 2007 16:54:51 GMT
Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_fsheap.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_fsheap.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_fsheap.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_fsheap.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,1029 @@
+#ifndef UIMA_LOWLEVEL_FSHEAP_HPP
+#define UIMA_LOWLEVEL_FSHEAP_HPP
+
+/** \file lowlevel_fsheap.hpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+
+#include "uima/lowlevel_typesystem.hpp"
+#include "uima/lowlevel_internal_heap.hpp"
+
+#include "uima/internal_typeshortcuts.hpp"
+#include "uima/cas.hpp"
+#include "uima/arrayfs.hpp"
+
+#ifndef NDEBUG
+#include <iostream>
+#endif
+
+#include <vector>
+
+#if defined( _MSC_VER )
+#pragma warning( push )
+#pragma warning( disable : 4311 )
+#pragma warning( disable : 4312 )
+#endif
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+  class CAS;
+  class XMLDumpWriter;
+  class LocalSofaDataStream;
+  namespace internal {
+    class CASSerializer;
+    class CASDeserializer;
+    class FSPromoter;
+  }
+  namespace lowlevel {
+    class DefaultFSIterator;
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+
+namespace uima {
+  namespace lowlevel {
+
+    /**
+     * The Feature structure heap;
+     * Note: this implementation used to contain temporary and permanent heaps
+     *       but the permanent feature has been removed.
+     */
+    class UIMA_LINK_IMPORTSPEC FSHeap {
+      friend class uima::CAS;
+      friend class uima::internal::CASSerializer;
+      friend class uima::internal::CASDeserializer;
+      friend class uima::internal::FSPromoter;
+      friend class uima::lowlevel::DefaultFSIterator;
+      friend class uima::XCASDeserializerHandler;
+      friend class uima::XMLDumpWriter;
+      friend class uima::LocalSofaDataStream;
+/*  VC++ 8 rejects all these forms of friend declaration
+     so method getCArrayFromFS has been made public
+#ifdef _MSC_VER
+      friend class uima::BasicArrayFS;
+#else
+      template<class,const uima::lowlevel::TyFSType> friend class uima::BasicArrayFS;
+#endif
+      // VC++ 7.1 rejects the "correct" declaration with:
+      //   C2888: 'uima::BasicArrayFS' : symbol cannot be defined within namespace 'lowlevel'
+*/
+    public:
+      typedef enum {
+        PERMANENT,
+        TEMPORARY
+      }
+      EnHeap;
+
+    private:
+      typedef internal::Heap<TyHeapCell> TyFSHeap;
+      typedef internal::Heap<UChar> TyStringHeap;
+      typedef uima::lowlevel::internal::Heap<TyHeapCell> TyStringRefHeap;
+
+      typedef uima::lowlevel::internal::Heap<char> Ty8BitHeap;
+      typedef uima::lowlevel::internal::Heap<short> Ty16BitHeap;
+      typedef uima::lowlevel::internal::Heap<INT64> Ty64BitHeap;
+
+
+      TyFSHeap iv_clTemporaryHeap;
+      TyStringHeap iv_clTemporaryStringHeap;
+      TyStringRefHeap iv_clTemporaryStringRefHeap;
+      //support for 8, 32, 64 bit heap
+      Ty8BitHeap iv_clTemporary8BitHeap;
+      Ty16BitHeap iv_clTemporary16BitHeap;
+      Ty64BitHeap iv_clTemporary64BitHeap;
+
+
+      TypeSystem const & iv_rclTypeSystem;
+
+      // internal helpers to set feature structures on the heap
+      //   without type checking
+      void setFeatureInternal(TyFS, TyFSFeature, TyFS);
+      TyFS getFeatureInternal(TyFS, TyFSFeature) const;
+
+      /**
+       * helper function to set the string ref heap entry located
+       * at pointerIntoStringRefHeap to point to s.
+       */
+      void setStringRef(TyFS offsetIntoStringRefHeap,
+                        TyFS offsetIntoStringHeap);
+
+      TyFSHeap& getHeap() {
+        return iv_clTemporaryHeap;
+      }
+
+      TyStringHeap& getStringHeap() {
+        return iv_clTemporaryStringHeap;
+      }
+
+      TyStringRefHeap & getStringRefHeap() {
+        return iv_clTemporaryStringRefHeap;
+      }
+
+      //support for 8, 32, 64 bit heap
+      Ty8BitHeap & get8BitHeap() {
+        return iv_clTemporary8BitHeap;
+      }
+      Ty16BitHeap & get16BitHeap() {
+        return iv_clTemporary16BitHeap;
+      }
+      Ty64BitHeap & get64BitHeap() {
+        return iv_clTemporary64BitHeap;
+      }
+
+
+
+      FSHeap();
+      FSHeap(FSHeap const &);
+      FSHeap & operator=(FSHeap const &);
+
+    protected:
+      
+      char const * get8BitArray(TyFS tyFs) const;
+
+      short const * get16BitArray(TyFS tyFs) const;
+
+      INT64 const * get64BitArray(TyFS tyFs) const;
+
+    public:
+      /**
+       * Construct a heap with respect to a type system.
+       * @param numberOfHeapCells initial heap size
+       */
+      FSHeap(TypeSystem const & rclTypeSystem,
+             size_t uiFSHeapPageSize,
+             size_t uiStringHeapPageSize,
+             size_t uiStringRefHeapPageSize);
+
+      FSHeap(TypeSystem const & rclTypeSystem,
+             size_t uiFSHeapPageSize,
+             size_t uiStringHeapPageSize,
+             size_t uiStringRefHeapPageSize,
+             size_t uiMinHeapPageSize);
+
+
+      ~FSHeap();
+
+      static TyFS const INVALID_FS;
+
+      /**
+       * get the C-style array from an array FS (const version).
+       */
+      TyHeapCell const * getCArrayFromFS(TyFS) const; //was public
+
+
+	  /** 
+        * get the C-style array from an array FS (non-const version).
+        */
+      TyHeapCell * getCArrayFromFS(TyFS);
+
+      /**
+       * Helper function to provide a unique ID for a feature structure
+       *
+       */
+      TyFS getUniqueID(uima::lowlevel::TyHeapCell const tyFs) const {
+        return tyFs;
+      }
+
+      /**
+       * check if a feature structure (of a non built-in type) actually lives within this heap.
+       */
+      bool resides(TyFS tyFS) const {
+        return iv_clTemporaryHeap.resides(tyFS);
+      }
+
+      /**
+       * check if a feature structure is valid w.r.t. this heap.
+       */
+      bool isValid(TyFS tyFS) const {
+        // second condition is false if heap was resetted
+        return resides(tyFS) && ( tyFS != (TyFS) TypeSystem::INVALID_TYPE );
+      }
+
+      TypeSystem const & getTypeSystem() const {
+        return iv_rclTypeSystem;
+      }
+
+      /**
+       * erases all data on the specified heap.
+       */
+      void reset();
+
+      /**
+       * create a feature structure of some type.
+       * ("high-end" variant).
+       * @param tyFeatureNumber the number of features for this type
+       */
+      TyFS createFS(TyFSType tyType, TyFeatureOffset tyFeatureNumber) {
+        assert( iv_rclTypeSystem.isValidType( tyType ) );
+        assert( tyType != uima::internal::gs_tyIntegerType );
+        assert( tyType != uima::internal::gs_tyFloatType );
+        assert( ! iv_rclTypeSystem.subsumes(uima::internal::gs_tyStringType, tyType) );
+        assert( iv_rclTypeSystem.getFeatureNumber(tyType) == tyFeatureNumber );
+        TyFSHeap & rtyHeap = getHeap();
+        TyFS tyResult = rtyHeap.increaseHeap(tyFeatureNumber + 1);
+        rtyHeap.setHeapValue(tyResult,(TyHeapCell) tyType);
+        return tyResult;
+      }
+
+      /**
+       * create a feature structure on the temporary heap where the size of the type is
+       * already known.
+       */
+      TyFS createFSWithSize(TyFSType tyType, TyFeatureOffset tyFeatureNumber) {
+        return createFS(tyType, tyFeatureNumber);
+      }
+
+      /**
+       * create a feature structure of some type.
+       */
+      TyFS createFS(TyFSType tyType) {
+        TyFeatureOffset tyNum = iv_rclTypeSystem.getFeatureNumber(tyType);
+        return createFS(tyType, tyNum);
+      }
+
+      /**
+       * create an array fs with size <code>uiSize</code>
+       * on the specified heap.
+       */
+      TyFS createArrayFS(TyFSType tyType, size_t uiSize) {
+        assert( iv_rclTypeSystem.isValidType( tyType ) );
+        assert( iv_rclTypeSystem.getFeatureNumber(tyType) == 0 );
+        assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, tyType ) );
+        TyFSHeap & rtyHeap = getHeap();
+        Ty8BitHeap & rty8BitHeap = get8BitHeap();
+        Ty16BitHeap & rty16BitHeap = get16BitHeap();
+        Ty64BitHeap & rty64BitHeap = get64BitHeap();
+
+        TyFS tyResult;
+        if (tyType == uima::internal::gs_tyLongArrayType ||
+            tyType == uima::internal::gs_tyDoubleArrayType) {
+
+          tyResult = rtyHeap.increaseHeap(3);
+          TyFS ty64BitHeapResult = rty64BitHeap.increaseHeap(uiSize);
+          rtyHeap.setHeapValue(tyResult, (TyHeapCell) tyType);
+          rtyHeap.setHeapValue(tyResult+1, (TyHeapCell) uiSize);
+          rtyHeap.setHeapValue(tyResult+2, (TyHeapCell) ty64BitHeapResult);
+        }
+        else if (tyType == uima::internal::gs_tyBooleanArrayType ||
+                 tyType == uima::internal::gs_tyByteArrayType) {
+
+          tyResult = rtyHeap.increaseHeap(3);
+          TyFS ty8BitHeapResult = rty8BitHeap.increaseHeap(uiSize);
+          rtyHeap.setHeapValue(tyResult, (TyHeapCell) tyType);
+          rtyHeap.setHeapValue(tyResult+1, (TyHeapCell) uiSize);
+          rtyHeap.setHeapValue(tyResult+2, (TyHeapCell) ty8BitHeapResult);
+        } else if (tyType == uima::internal::gs_tyShortArrayType) {
+
+          tyResult = rtyHeap.increaseHeap(3);
+          TyFS ty16BitHeapResult = rty16BitHeap.increaseHeap(uiSize);
+          rtyHeap.setHeapValue(tyResult, (TyHeapCell) tyType);
+          rtyHeap.setHeapValue(tyResult+1, (TyHeapCell) uiSize);
+          rtyHeap.setHeapValue(tyResult+2, (TyHeapCell) ty16BitHeapResult);
+        }
+        else {
+          // a 32bit type. 1 cell for the type, 1 for length, uiSize many for the array data
+
+          tyResult = rtyHeap.increaseHeap(2 + uiSize);
+          rtyHeap.setHeapValue(tyResult,(TyHeapCell) tyType);
+          assert( sizeof(INT32) <= sizeof(TyHeapCell) );
+          rtyHeap.setHeapValue(tyResult+1,(TyHeapCell) uiSize);
+        }
+        return tyResult;
+      }
+
+      /**
+       * get the <code>Lstring</code> from a feature structure.
+       * Precondition: <code>tyFS</code> must be of type string.
+       */
+      UnicodeStringRef getFSAsString(TyFS tyFS) const;
+
+      /**
+       * returns the type of a feature structure.
+       */
+      TyFSType getType(TyFS tyFs) const;
+
+      /**
+       * method for fast access of feature values.
+       * Use this in combination with InternalTypeSystem::getFeatureOffset.
+       */
+      TyFS getFeatureWithOffset(TyFS tyFs, TyFeatureOffset tyOffset) const;
+
+      /**
+       * method for fast setting of feature values.
+       * Use this in combination with InternalTypeSystem::getFeatureOffset.
+       */
+      void setFeatureWithOffset(TyFS tyFs, TyFeatureOffset tyOffset, TyFS tyValue);
+
+      /**
+       * store copy of string on the specified heap.
+       * @return the reference to the copied string.
+       */
+      int addString(UnicodeStringRef const & uls) {
+        size_t l = uls.length();
+        TyStringHeap & rtyStringHeap = getStringHeap();
+        int p = rtyStringHeap.increaseHeap(l + 1);
+        assert( (int)(2*l) == uls.getSizeInBytes() );
+        memcpy(rtyStringHeap.getHeapStart()+p, uls.getBuffer(), uls.getSizeInBytes() );
+        return p;
+      }
+
+      //store long / double value 64 bit heap
+
+      TyFS addLong(INT64 value) {
+        Ty64BitHeap & rty64BitHeap = get64BitHeap();
+        TyFS p = rty64BitHeap.increaseHeap(sizeof(INT64) );
+        rty64BitHeap.setHeapValue(p, value);
+        return p;
+      }
+
+      TyFS addDouble(double value) {
+        Ty64BitHeap & rty64BitHeap = get64BitHeap();
+        TyFS p = rty64BitHeap.increaseHeap(sizeof(INT64) );
+        INT64 int64Val;
+        memcpy(&int64Val, &value, sizeof(INT64));
+        rty64BitHeap.setHeapValue(p, int64Val);
+        return p;
+      }
+
+      /**
+       * return copy of string on the stringHeap.
+       * @return the reference to the string.
+       */
+      UnicodeStringRef getString(int strRef) {
+        // convert from logical string offset to absolute offset into refHeap
+        if (strRef == 0) {
+          return UnicodeStringRef();
+        }
+        strRef = 1 + 2*(strRef-1);
+        return UnicodeStringRef( iv_clTemporaryStringHeap.getHeapStart()+
+                                 iv_clTemporaryStringRefHeap.getHeapValue(strRef),
+                                 (size_t) iv_clTemporaryStringRefHeap.getHeapValue(strRef+1));
+      }
+
+      /**
+       * store a copy of a string on the specified heap.
+       * @return the reference to the copied string.
+       */
+      int addString(icu::UnicodeString const & uls) {
+        return addString(UnicodeStringRef(uls.getBuffer(), uls.length()));
+      }
+
+      /**
+       * returns if the feature value tyFeat of feature structure tyFS
+       * was already touched, i.e., used in a setFeature() or getFeature() call.
+       */
+      bool isUntouchedFSValue(TyFS tyFS, TyFSFeature tyFeat) const;
+
+      /**
+       * get the value of feature <code>tyFeat</code> on feature structure <code>tyFS</code>.
+       */
+      TyFS getFSValue(TyFS tyFS, TyFSFeature tyFeat) const;
+
+      /**
+       * set the feature <code>tyFeat</code> on feature structure <code>tyFS</code>
+       * to value <code>tyValue</code>,
+       */
+      void setFSValue(TyFS tyFS, TyFSFeature tyFeat, TyFS tyValue);
+
+      /**
+       * get the size of an array FS.
+       */
+      size_t getArraySize(TyFS) const;
+
+      /**
+       * gets the start pos of this array in the appropriate heap
+      * where values of this array type is stored.
+       */
+      TyHeapCell getArrayOffset(TyFS) const;
+
+
+      /*@{*/
+      /**
+       * @name Conversion Functions. Use only with the set/getFeatureWithOffset methods.
+       */
+
+      /**
+       * convert an fs into an integer.
+       */
+      static int getFSAsInt(TyFS tyFs) {
+        return(int) tyFs;
+      }
+
+      /**
+       * convert an fs into a float.
+       */
+      static float getFSAsFloat(TyFS tyFs) {
+        assertWithMsg( sizeof(float) <= sizeof(TyHeapCell), "Port required");
+        float f;
+        memcpy(&f, &tyFs, 4);
+        return f;
+      }
+
+      /**
+       * convert an fs into a bool.
+       */
+      static bool getFSAsBoolean(TyFS tyFs) {
+        if (tyFs==1)
+          return true;
+        else return false;
+      }
+
+      /**
+       * convert an fs into a byte.
+       */
+      static char getFSAsByte(TyFS tyFs) {
+        //assertWithMsg( sizeof(float) <= sizeof(TyHeapCell), "Port required");
+        return (char) tyFs;
+      }
+
+      /**
+       * convert an fs into a short.
+       */
+      static short getFSAsShort(TyFS tyFs) {
+        //assertWithMsg( sizeof(float) <= sizeof(TyHeapCell), "Port required");
+        return (short)tyFs;
+      }
+
+
+      inline INT64 getFSAsLong(TyFS tyFS) const {
+        if (tyFS == 0) {
+          return '\n';
+        }
+        assert( iv_clTemporary64BitHeap.debugIsValidHeapCell(tyFS) );
+        return (INT64) iv_clTemporary64BitHeap.getHeapValue(tyFS);
+      }
+
+      inline double getFSAsDouble(TyFS tyFS) const {
+        if (tyFS == 0) {
+          return '\n';
+        }
+        assert( iv_clTemporary64BitHeap.debugIsValidHeapCell(tyFS) );
+        INT64 int64Val = iv_clTemporary64BitHeap.getHeapValue(tyFS);
+        double d;
+        memcpy(&d, &int64Val, sizeof(double));
+        return d;
+      }
+
+
+      /**
+       * convert an integer into an fs.
+       */
+      static TyFS getAsFS(int i) {
+        return(TyFS) i;
+      }
+
+      /**
+       * convert a float into an fs.
+       */
+      static TyFS getAsFS(float f) {
+        assertWithMsg( sizeof(float) <= sizeof(TyHeapCell), "Port required");
+        TyFS tyFs;
+        memcpy(&tyFs, &f, 4);
+        return tyFs;
+      }
+
+      /**
+       * convert a byte  into an fs.
+       */
+      static TyFS getAsFS(char f) {
+        assertWithMsg( sizeof(char) <= sizeof(TyHeapCell), "Port required");
+        return (TyFS)f;
+      }
+
+      /**
+       * convert a short  into an fs.
+       */
+      static TyFS getAsFS(short f) {
+        assertWithMsg( sizeof(short) <= sizeof(TyHeapCell), "Port required");
+        return (TyFS)f;
+      }
+
+      /**
+       * convert a byte  into an fs.
+       */
+      static TyFS getAsFS(bool f) {
+        assertWithMsg( sizeof(WORD8) <= sizeof(TyHeapCell), "Port required");
+        TyFS tyFs = 0;
+        if (f) {
+          tyFs=1; //true
+        } else {
+          tyFs=2; //false
+        }
+        return tyFs;
+      }
+
+      TyFS getLongAsFS(INT64);
+      TyFS getDoubleAsFS(double);
+
+
+
+
+      /**
+       * convert a stringRef into an offset into the StringRefHeap.
+       * This method is non-const since an entry on the string ref heap
+       * is created.
+       */
+      TyFS getStringAsFS(int crStringRef);
+
+      /*@}*/
+
+      /*@{*/
+      /**
+       * @name Special methods for features with built-in types values.
+       */
+      void setIntValue(TyFS, TyFSFeature, int);
+      void setFloatValue(TyFS, TyFSFeature, float);
+      void setStringValue(TyFS, TyFSFeature, int strRef);
+
+      void setByteValue(TyFS, TyFSFeature, char );
+      void setShortValue(TyFS, TyFSFeature, short );
+      void setBooleanValue(TyFS, TyFSFeature, bool );
+      void setLongValue(TyFS, TyFSFeature, INT64 ref);
+      void setDoubleValue(TyFS, TyFSFeature, double);
+
+      int getIntValue(TyFS, TyFSFeature) const;
+      float getFloatValue(TyFS, TyFSFeature) const;
+      UnicodeStringRef getStringValue(TyFS, TyFSFeature) const;
+
+      bool getBooleanValue(TyFS,TyFSFeature) const;
+      char getByteValue(TyFS,TyFSFeature) const;
+      short getShortValue(TyFS,TyFSFeature) const;
+      INT64 getLongValue(TyFS,TyFSFeature) const;
+      double getDoubleValue(TyFS,TyFSFeature) const;
+
+      //methods for setting ArrayFS values in the appropriate heap
+      void setArrayElement(int val, TyHeapCell offset );
+      void setArrayElement(float val, TyHeapCell offset );
+
+      void setArrayElement(char val, TyHeapCell offset );
+      void setArrayElement(short val, TyHeapCell offset );
+      void setArrayElement(bool val, TyHeapCell offset );
+      void setArrayElement(INT64 val, TyHeapCell offset);
+      void setArrayElement(double, TyHeapCell offset);
+
+      char getByte( TyHeapCell offset );
+      short getShort(TyHeapCell offset );
+      bool getBoolean(TyHeapCell offset );
+      INT64 getLong(TyHeapCell offset);
+      double getDouble(TyHeapCell offset);
+
+
+      /*@}*/
+
+
+      /**
+       * shallow copy of feature structures.
+       * ints, floats, and strings are copied "by-value".
+       * If featnum == 0 the types of <code>tyTarget</code> and <code>tySource</code> should be equal.
+       * Otherwise, just the first featNum features of source are copied to target
+       * (no questions asked).
+       */
+      void copyFeatures(TyFS tyTarget, TyFS tySource, size_t featNum = 0);
+
+      /**
+       * print an FS.
+       */
+      void printFS(ostream&, TyFS) const;
+
+//#ifndef NDEBUG
+      // debug methods
+      TyHeapCell* getHeapStart() const;
+      bool debugIsValidHeapCell(TyHeapCell) const;
+      bool debugIsConsistent() const;
+      void print(ostream&) const;
+//#endif
+
+    };
+
+  }
+}
+
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+
+    inline TyFSType FSHeap::getType(TyFS tyFs) const {
+      assert( debugIsValidHeapCell(tyFs) );
+      TyFSType tyType = (TyFSType) iv_clTemporaryHeap.getHeapValue(tyFs);
+      assert( iv_rclTypeSystem.isValidType(tyType) );
+      return tyType;
+    }
+
+
+    inline TyFS FSHeap::getFeatureWithOffset(TyFS tyFs, TyFeatureOffset tyOffset) const {
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( debugIsValidHeapCell(tyFs + tyOffset) );
+      assert( tyOffset > 0 );
+      assert( tyOffset <= iv_rclTypeSystem.getFeatureNumber( getType(tyFs) ));
+      return(TyFS) iv_clTemporaryHeap.getHeapValue(tyFs + tyOffset);
+    }
+
+    inline void FSHeap::setFeatureWithOffset(TyFS tyFs, TyFeatureOffset tyOffset, TyFS tyValue) {
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( debugIsValidHeapCell(tyFs + tyOffset) );
+      assert( tyOffset > 0 );
+      assert( tyOffset <= iv_rclTypeSystem.getFeatureNumber( getType(tyFs) ));
+      iv_clTemporaryHeap.setHeapValue(tyFs + tyOffset, tyValue);
+    }
+
+    inline void FSHeap::setStringRef(TyFS strHeapRef, TyFS strRef) {
+      // convert from logical string offset to absolute offset into refHeap
+      strHeapRef = 1 + 2*(strHeapRef-1);
+
+      // set offset into StringHeap
+      iv_clTemporaryStringRefHeap.setHeapValue(strHeapRef, strRef);
+
+      // set length
+      iv_clTemporaryStringRefHeap.setHeapValue(strHeapRef+1,
+          u_strlen(iv_clTemporaryStringHeap.getHeapStart()+strRef) );
+    }
+
+    inline UnicodeStringRef FSHeap::getFSAsString(TyFS tyFS) const {
+      if (tyFS == 0) {
+        return UnicodeStringRef();
+      }
+      assert( iv_clTemporaryStringRefHeap.debugIsValidHeapCell(tyFS) );
+      // convert from logical string offset to absolute offset into refHeap
+      tyFS = 1 + 2*(tyFS-1);
+      return UnicodeStringRef( iv_clTemporaryStringHeap.getHeapStart()+
+                               iv_clTemporaryStringRefHeap.getHeapValue(tyFS),
+                               (size_t) iv_clTemporaryStringRefHeap.getHeapValue(tyFS+1));
+    }
+
+    inline TyFS FSHeap::getStringAsFS(int crStringRef) {
+      // increase string ref heap by 2
+      TyFS stringRef = iv_clTemporaryStringRefHeap.increaseHeap(2);
+      // convert to local string offset
+      stringRef = 1 + ((stringRef-1)/2);
+      setStringRef(stringRef, crStringRef);
+      return stringRef;
+    }
+
+    inline TyFS FSHeap::getLongAsFS(INT64 l) {
+      return addLong(l);
+    }
+
+    inline TyFS FSHeap::getDoubleAsFS(double l) {
+      return addDouble(l);
+    }
+
+    inline TyFS FSHeap::getFeatureInternal(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.isAppropriateFeature( getType(tyFs), tyFeature ) );
+      TyFeatureOffset tyFeatureOffset = iv_rclTypeSystem.getFeatureOffset(tyFeature);
+      assert( debugIsValidHeapCell(tyFs + tyFeatureOffset) );
+      TyFS tyFsCell = iv_clTemporaryHeap.getHeapValue(tyFs + tyFeatureOffset);
+      return tyFsCell;
+    }
+
+    inline bool FSHeap::isUntouchedFSValue(TyFS tyFS, TyFSFeature tyFeature) const {
+      TyFS tyFsCell = getFeatureInternal(tyFS, tyFeature);
+      return tyFsCell == INVALID_FS;
+    }
+
+
+    inline int FSHeap::getIntValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_INTEGER) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsInt(tyResult);
+    }
+
+    inline float FSHeap::getFloatValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_FLOAT) );
+      assertWithMsg( sizeof(float) <= sizeof(TyHeapCell*), "Port required");
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsFloat(tyResult);
+    }
+
+    inline UnicodeStringRef FSHeap::getStringValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyStringType, iv_rclTypeSystem.getRangeType(tyFeature) ) );
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsString(tyResult);
+    }
+
+    inline bool FSHeap::getBooleanValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyBooleanType, iv_rclTypeSystem.getRangeType(tyFeature) ) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsBoolean(tyResult);
+    }
+
+
+    inline char FSHeap::getByteValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyByteType, iv_rclTypeSystem.getRangeType(tyFeature) ) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsByte(tyResult);
+    }
+
+    inline short FSHeap::getShortValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyShortType, iv_rclTypeSystem.getRangeType(tyFeature) ) );
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsShort(tyResult);
+    }
+
+    inline INT64 FSHeap::getLongValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyLongType, iv_rclTypeSystem.getRangeType(tyFeature) ) );
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsLong(tyResult);
+    }
+
+    inline double FSHeap::getDoubleValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyDoubleType, iv_rclTypeSystem.getRangeType(tyFeature) ) );
+      TyFS tyResult = getFeatureInternal(tyFs, tyFeature);
+      return getFSAsDouble(tyResult);
+    }
+
+
+    inline TyHeapCell const * FSHeap::getCArrayFromFS(TyFS tyFs) const {
+      assert( isValid(tyFs) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, getType(tyFs) ) );
+      assert( iv_rclTypeSystem.getFeatureNumber( getType(tyFs) ) == 0 );
+      if ( 0 == iv_clTemporaryHeap.getHeapValue(tyFs + 1)) {
+        return NULL;
+      }
+      return(TyHeapCell const *) iv_clTemporaryHeap.getHeapStart() + tyFs + 2;
+    }
+
+    inline TyHeapCell * FSHeap::getCArrayFromFS(TyFS tyFs) {
+      FSHeap const * cpConstThis = this;
+      return CONST_CAST(TyHeapCell *, cpConstThis->getCArrayFromFS(tyFs) );
+    }
+
+    inline char const * FSHeap::get8BitArray(TyFS tyFs) const {
+      assert( isValid(tyFs) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, getType(tyFs) ) );
+      assert( iv_rclTypeSystem.getFeatureNumber( getType(tyFs) ) == 0 );
+      if ( 0 == iv_clTemporaryHeap.getHeapValue(tyFs + 1)) {
+        return NULL;
+      }
+      return(char const *) this->iv_clTemporary8BitHeap.getHeapStart() + iv_clTemporaryHeap.getHeapValue(tyFs + 2);
+    }
+
+    inline short const * FSHeap::get16BitArray(TyFS tyFs) const {
+      assert( isValid(tyFs) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, getType(tyFs) ) );
+      assert( iv_rclTypeSystem.getFeatureNumber( getType(tyFs) ) == 0 );
+      if ( 0 == iv_clTemporaryHeap.getHeapValue(tyFs + 1)) {
+        return NULL;
+      }
+      return(short const *) this->iv_clTemporary16BitHeap.getHeapStart() + iv_clTemporaryHeap.getHeapValue(tyFs + 2);
+    }
+
+    inline INT64 const * FSHeap::get64BitArray(TyFS tyFs) const {
+      assert( isValid(tyFs) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, getType(tyFs) ) );
+      assert( iv_rclTypeSystem.getFeatureNumber( getType(tyFs) ) == 0 );
+      if ( 0 == iv_clTemporaryHeap.getHeapValue(tyFs + 1)) {
+        return NULL;
+      }
+
+      return(INT64 const *) this->iv_clTemporary64BitHeap.getHeapStart() + iv_clTemporaryHeap.getHeapValue(tyFs + 2);
+    }
+
+    inline size_t FSHeap::getArraySize(TyFS tyFs) const {
+      assert( isValid(tyFs) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, getType(tyFs) ) );
+      assert( sizeof(WORD32) <= sizeof(uima::lowlevel::TyFS) );
+      return(size_t) iv_clTemporaryHeap.getHeapValue(tyFs + 1);
+    }
+
+    inline TyHeapCell FSHeap::getArrayOffset(TyFS tyFs) const {
+      assert( isValid(tyFs) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, getType(tyFs) ) );
+      assert( sizeof(WORD32) <= sizeof(uima::lowlevel::TyFS) );
+      TyFSType typecode = getType(tyFs);
+      if (typecode == uima::internal::gs_tyBooleanArrayType ||
+          typecode == uima::internal::gs_tyByteArrayType ||
+          typecode == uima::internal::gs_tyShortArrayType ||
+          typecode == uima::internal::gs_tyLongArrayType ||
+          typecode == uima::internal::gs_tyDoubleArrayType)  {
+        return(size_t) iv_clTemporaryHeap.getHeapValue(tyFs + 2);
+      } else  {
+        return tyFs+2;
+      }
+    }
+
+
+//////////////////////////////////////////////////////////////////////////
+
+
+    inline void FSHeap::setFeatureInternal(TyFS tyFs, TyFSFeature tyFeature, TyFS tyValue) {
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.isAppropriateFeature( getType(tyFs), tyFeature ) );
+      TyFeatureOffset tyFeatureOffset = iv_rclTypeSystem.getFeatureOffset(tyFeature);
+      TyHeapCell tyFsCell = tyFs + tyFeatureOffset;
+      assert( debugIsValidHeapCell(tyFsCell) );
+      iv_clTemporaryHeap.setHeapValue(tyFsCell, tyValue);
+    }
+
+    inline void FSHeap::setFSValue(TyFS tyFs, TyFSFeature tyFeature, TyFS tyValue) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( debugIsValidHeapCell(tyFs) );
+      assert( resides(tyFs) );
+      assert( iv_rclTypeSystem.isAppropriateFeature( getType(tyFs), tyFeature ) );
+#ifndef NDEBUG
+      if (tyValue != INVALID_FS) {
+        assert( debugIsValidHeapCell(tyValue) );
+        if (iv_rclTypeSystem.subsumes( uima::internal::gs_tyFSArrayType, iv_rclTypeSystem.getRangeType( tyFeature ) )) {
+          assert(resides(tyValue));
+        } else if ( !iv_rclTypeSystem.subsumes( uima::internal::gs_tyStringType, iv_rclTypeSystem.getRangeType( tyFeature ) ) ) {
+          assert( resides(tyValue) );
+          assert( iv_rclTypeSystem.subsumes( iv_rclTypeSystem.getRangeType( tyFeature ), getType(tyValue) ) );
+        } else {
+          assert( iv_clTemporaryStringRefHeap.resides(tyValue) );
+        }
+      }
+#endif
+      setFeatureInternal(tyFs, tyFeature, tyValue);
+    }
+
+    inline TyFS FSHeap::getFSValue(TyFS tyFs, TyFSFeature tyFeature) const {
+      TyFS tyFsCell = getFeatureInternal(tyFs, tyFeature);
+#ifndef NDEBUG
+      if (tyFsCell != INVALID_FS) {
+        if ( ! iv_rclTypeSystem.subsumes( uima::internal::gs_tyStringType, iv_rclTypeSystem.getRangeType( tyFeature ) ) ) {
+          assert( iv_rclTypeSystem.subsumes( iv_rclTypeSystem.getRangeType(tyFeature), getType(tyFsCell) ) );
+        }
+      }
+#endif
+      return tyFsCell;
+    }
+
+    inline void FSHeap::setIntValue(TyFS tyFs, TyFSFeature tyFeature, int iValue) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_INTEGER) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, (TyFS)iValue );
+    }
+
+    inline void FSHeap::setFloatValue(TyFS tyFs, TyFSFeature tyFeature, float fValue) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_FLOAT) );
+      assertWithMsg( sizeof(float) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, getAsFS(fValue) );
+    }
+
+
+    inline void FSHeap::setBooleanValue(TyFS tyFs, TyFSFeature tyFeature, bool ref) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_BOOLEAN) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, getAsFS(ref) );
+    }
+
+
+    inline void FSHeap::setByteValue(TyFS tyFs, TyFSFeature tyFeature, char ref) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_BYTE) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, getAsFS(ref) );
+    }
+
+    inline void FSHeap::setShortValue(TyFS tyFs, TyFSFeature tyFeature, short ref) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_SHORT) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, getAsFS(ref) );
+    }
+
+    inline void FSHeap::setLongValue(TyFS tyFs, TyFSFeature tyFeature, INT64 ref) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_LONG) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, addLong(ref) );
+    }
+
+    inline void FSHeap::setDoubleValue(TyFS tyFs, TyFSFeature tyFeature, double ref) {
+      assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+      assert( iv_rclTypeSystem.getTypeName( iv_rclTypeSystem.getRangeType(tyFeature) )  == icu::UnicodeString(CAS::TYPE_NAME_DOUBLE) );
+      assertWithMsg( sizeof(int) <= sizeof(TyHeapCell*), "Port required");
+      setFeatureInternal(tyFs, tyFeature, addDouble(ref) );
+    }
+
+
+    inline void FSHeap::setArrayElement(int tyValue, TyHeapCell tyFsCell) {
+      this->iv_clTemporaryHeap.setHeapValue(tyFsCell, tyValue);
+    }
+    inline void FSHeap::setArrayElement(float tyValue, TyHeapCell tyFsCell) {
+      this->iv_clTemporaryHeap.setHeapValue(tyFsCell, getAsFS(tyValue));
+    }
+
+    inline void FSHeap::setArrayElement(bool tyValue, TyHeapCell tyFsCell) {
+      iv_clTemporary8BitHeap.setHeapValue(tyFsCell, tyValue);
+    }
+    inline void FSHeap::setArrayElement(char tyValue, TyHeapCell tyFsCell) {
+      iv_clTemporary8BitHeap.setHeapValue(tyFsCell, tyValue);
+    }
+    inline void FSHeap::setArrayElement(short tyValue, TyHeapCell tyFsCell) {
+      iv_clTemporary16BitHeap.setHeapValue(tyFsCell, tyValue);
+    }
+    inline void FSHeap::setArrayElement(INT64 tyValue, TyHeapCell tyFsCell) {
+      iv_clTemporary64BitHeap.setHeapValue(tyFsCell, tyValue);
+    }
+    inline void FSHeap::setArrayElement(double tyValue, TyHeapCell tyFsCell) {
+      INT64 int64Val;
+      memcpy(&int64Val, &tyValue, sizeof(INT64));
+      iv_clTemporary64BitHeap.setHeapValue(tyFsCell, int64Val);
+    }
+
+    inline bool FSHeap::getBoolean(TyHeapCell tyFsCell) {
+      char val = iv_clTemporary8BitHeap.getHeapValue(tyFsCell);
+      if
+      (val==1) return true;
+      else
+        return false;
+    }
+    inline char FSHeap::getByte(TyHeapCell tyFsCell) {
+      return iv_clTemporary8BitHeap.getHeapValue(tyFsCell);
+    }
+    inline short FSHeap::getShort(TyHeapCell tyFsCell) {
+      return iv_clTemporary16BitHeap.getHeapValue(tyFsCell);
+    }
+    inline INT64 FSHeap::getLong(TyHeapCell tyFsCell) {
+      return iv_clTemporary64BitHeap.getHeapValue(tyFsCell);
+    }
+    inline double FSHeap::getDouble(TyHeapCell tyFsCell) {
+      INT64 int64Val = iv_clTemporary64BitHeap.getHeapValue(tyFsCell);
+      double d;
+      memcpy(&d, &int64Val, sizeof(double));
+      return d;
+    }
+
+
+
+  }
+}
+
+
+/* ----------------------------------------------------------------------- */
+
+#if defined( _MSC_VER )
+#pragma warning( pop )
+#endif
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_fsheap.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_index.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_index.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_index.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_index.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,165 @@
+#ifndef UIMA_LOWLEVEL_INDEX_HPP
+#define UIMA_LOWLEVEL_INDEX_HPP
+/** \file lowlevel_index.hpp .
+-----------------------------------------------------------------------------
+
+
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp" // must be first file to be included to get pragmas
+#include <vector>
+#include <algorithm>
+#include <set>
+#include "uima/types.h"
+#include "uima/lowlevel_typedefs.hpp"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+  namespace lowlevel {
+    class IndexComparator;
+    class TypeSystem;
+    class FSHeap;
+    class IndexIterator;
+    class IndexRepository;
+    class FSFilter;
+    /*
+    namespace internal {
+       class CompositeIndex;
+    }
+    */
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+
+    /**
+     * The base class for all indexes.
+     */
+    class UIMA_LINK_IMPORTSPEC IndexABase {
+      friend class IndexRepository; // for access to add()
+//         friend class internal::CompositeIndex; // for access of reset()
+    protected:
+      IndexRepository const & iv_crIndexRepository;
+      FSHeap const & iv_crFSHeap;
+      TypeSystem const & iv_crTypeSystem;
+      uima::lowlevel::TyFSType iv_tyFSType;
+
+      IndexABase(IndexRepository const &, uima::lowlevel::TyFSType);
+
+      virtual ~IndexABase() {}
+
+      virtual void add(TyFS fs) = 0;
+      virtual void remove(TyFS fs) = 0;
+      virtual void reset() = 0;
+    public:
+      /**
+       * get the size of this index, i.e., how many feature structures it contains.
+       */
+      virtual size_t getSize() const = 0;
+
+      /**
+       * Find a feature structure within this index which matches <code>tyFS</code>
+       * with respect to the comparator of this index (i.e. where the <code>compare</code>
+       * method of <code>IndexComparator</code> returns 0). If no such feature structure
+       * is found, <code>INVALID_FS</code> is returned.
+       */
+      virtual TyFS find(TyFS tyFS) const;
+
+      /**
+       * create an iterator over this index.
+       */
+      virtual IndexIterator* createIterator() const = 0;
+
+      /**
+       * create an iterator over this index which contains only structures
+       * of the types indicated in <code>crTypes</code>.
+       * Precondition: All types must be subsumed by the type of this index
+       * (i.e. <code>getType()</code>.
+       */
+      virtual IndexIterator* createTypeSetIterator(set<uima::lowlevel::TyFSType> const & crTypes) const = 0;
+
+      /**
+       * create a filtered iterator over this index which filter
+       * <code>cpFilter</code>. All feature structures where the
+       * <code>isFiltered</code> method of the filter object returns true
+       * are skipped by the iterator.
+       */
+      IndexIterator* createFilteredIterator(FSFilter const * cpFilter) const;
+
+      /**
+       * Advanced use only:
+       * Returns a const pointer to an internal vector of feature structures.
+       * A value != NULL is returned _only_ if the implementing class actually
+       * uses a vector internally to store the FSs.
+       */
+      virtual vector<uima::lowlevel::TyFS> const * getVector() const {
+        return NULL;
+      }
+
+      uima::lowlevel::TyFSType getType() const {
+        return iv_tyFSType;
+      }
+
+      FSHeap const & getFSHeap() const {
+        return iv_crFSHeap;
+      }
+
+      IndexRepository const & getIndexRepository() const {
+        return iv_crIndexRepository;
+      }
+
+    };
+
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_index.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexcomparator.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexcomparator.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexcomparator.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexcomparator.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,143 @@
+#ifndef UIMA_LOWLEVEL_INDEXCOMPARATOR_HPP
+#define UIMA_LOWLEVEL_INDEXCOMPARATOR_HPP
+/** \file lowlevel_indexcomparator.hpp .
+-----------------------------------------------------------------------------
+
+
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp" // must be first file to be included to get pragmas
+#include "uima/cas.hpp"
+#include "uima/lowlevel_fsheap.hpp"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+  namespace lowlevel {
+    class IndexDefinition;
+  }
+}
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+
+
+    /**
+     * The abstract base class for all comparators used for creating indexes.
+     * @see uima::lowlevel::IndexRepository
+     */
+    class UIMA_LINK_IMPORTSPEC IndexComparator {
+    public:
+      typedef enum {
+        STANDARD_COMPARE,
+        REVERSE_STANDARD_COMPARE
+      } EnKeyFeatureComp;
+    protected:
+      typedef enum {
+        BUILTIN_TYPE_INTEGER,
+        BUILTIN_TYPE_FLOAT,
+        BUILTIN_TYPE_STRING,
+        BUILTIN_TYPE_BOOLEAN,
+        BUILTIN_TYPE_BYTE,
+        BUILTIN_TYPE_SHORT,
+        BUILTIN_TYPE_LONG,
+        BUILTIN_TYPE_DOUBLE,
+        BUILTIN_TYPE_INVALID
+      } EnBuiltinTypes;
+
+      IndexDefinition const & iv_indexDefinition;
+      TyFSType iv_tyType;
+
+      vector<TyFSFeature> iv_features;
+      vector<TyFeatureOffset> iv_offsets;
+      vector<EnBuiltinTypes> iv_appropTypes;
+      vector<EnKeyFeatureComp> iv_comparators;
+    public:
+      IndexComparator(IndexDefinition const & iv_indexDefinition,
+                      TyFSType tyType);
+      /**
+       * Create a comparator where STANDARD_COMPARE is assumed for all features.
+       * @param crKeyFeatures a list of key features (must have built-in range)
+       */
+      IndexComparator(IndexDefinition const & iv_indexDefinition,
+                      TyFSType tyType,
+                      vector<TyFSFeature> const & crKeyFeatures);
+
+      void addKey(TyFSFeature tyFeat, EnKeyFeatureComp tyComp);
+
+
+      /**
+       * Compare two feature structures.
+       * @return 1 if <code>tyFS1</code> is less than <code>tyFS2</code>,
+       *         -1 if <code>tyFS1</code> is greater than <code>tyFS2</code>,
+       *         0 if <code>tyFS1</code> equals <code>tyFS2</code>
+       */
+      int compare(uima::lowlevel::FSHeap const & heap, TyFS tyFS1, TyFS tyFS2) const;
+
+      /**
+       * return the type this comparator is capable to compare.
+       */
+      TyFSType getType() const {
+        return iv_tyType;
+      }
+
+      vector<EnKeyFeatureComp> const & getComparisonOps() const {
+        return iv_comparators;
+      }
+
+      vector<TyFSFeature> const & getKeyFeatures() const {
+        return iv_features;
+      }
+
+    };
+
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexcomparator.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexdefinition.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexdefinition.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexdefinition.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexdefinition.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,227 @@
+#ifndef UIMA_LOWLEVEL_INDEXDEFINITION_HPP
+#define UIMA_LOWLEVEL_INDEXDEFINITION_HPP
+/** \file lowlevel_indexdefinition.hpp .
+-----------------------------------------------------------------------------
+
+
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+
+#include <map>
+#include <vector>
+#include "uima/lowlevel_typedefs.hpp"
+#include "uima/lowlevel_indexcomparator.hpp"
+#include "unicode/unistr.h"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+  namespace lowlevel {
+    class TypeSystem;
+    class IndexComparator;
+    namespace internal {
+      class IndexFactory;
+    }
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+  namespace lowlevel {
+
+    /**
+     * This class contains all index definitions together with the factories
+     * needed for actually creating them.
+     */
+    class UIMA_LINK_IMPORTSPEC IndexDefinition {
+      friend class uima::lowlevel::IndexRepository;
+    public:
+      typedef icu::UnicodeString TyIndexID;
+      typedef enum {
+        enOrdered = 0,
+        enSet = 1,
+        enFIFO = 2,
+        enIndexKindNumber = 3
+      } EnIndexKind;
+    private:
+      TypeSystem const & iv_crTypeSystem;
+      // maps ids to index factories
+      map<TyIndexID, internal::IndexFactory*> iv_mapFactories;
+
+      // iv_mapIndexTypes[i] is the type of the index with ID i
+      map<TyIndexID, TyFSType> iv_mapIndexTypes;
+
+      // iv_mapIsPermanentFlags[i] is true if index with ID i contains permanent feature structures
+      map<TyIndexID, bool> iv_mapIsPermanentFlags;
+      vector<uima::lowlevel::IndexComparator*> iv_vecComparators;
+
+      bool iv_bIsCommitted;
+
+      /**
+       * checks if the index defined in the first four arguments is compatible to
+       * the one with ID crID.
+       */
+      bool isCompatibleIndexDefinition(EnIndexKind enIxKind,
+                                       TyFSType tyType,
+                                       vector<uima::lowlevel::TyFSFeature> const & crKeyFeatures,
+                                       vector<uima::lowlevel::IndexComparator::EnKeyFeatureComp> const & crComparators,
+                                       TyIndexID const & crID,
+                                       bool ) const;
+      /**
+       * create a factory for the index defined by the arguments to this method.
+       */
+      uima::lowlevel::internal::IndexFactory * createFactory(EnIndexKind enIxKind,
+          TyFSType,
+          IndexComparator const * pComparator) const;
+
+      void clear();
+
+      IndexDefinition(IndexDefinition const &);
+      IndexDefinition& operator=(IndexDefinition const &);
+
+    public:
+      IndexDefinition(uima::lowlevel::TypeSystem const &);
+      ~IndexDefinition();
+
+      TypeSystem const & getTypeSystem() const {
+        return iv_crTypeSystem;
+      }
+
+      void commit();
+
+      bool isCommitted() const {
+        return iv_bIsCommitted;
+      }
+
+      /*@{*/
+      /**
+       * @name Index Creation
+       */
+
+      /**
+       * add an index definition
+       *
+       * @param enIxKind the kind of the index
+       * @param tyType the most general type where the index should be introduced
+       * @param crKeyFeatures a vector of key features used for comparison
+       * @param crComparators a vector defining how the key features should be compared
+       * @param id the ID under which this index can be identified
+       * @param bIsPermanent flag indicating if this index contains only permanent feature structures
+       */
+      void defineIndex(EnIndexKind enIxKind,
+                       TyFSType tyType,
+                       vector<uima::lowlevel::TyFSFeature> const & crKeyFeatures,
+                       vector<uima::lowlevel::IndexComparator::EnKeyFeatureComp> const & crComparators,
+                       TyIndexID const & id,
+                       bool bIsPermanent = false);
+
+
+      /*@}*/
+
+      /**
+       * check if an index with ID <code>id</code> exists.
+       */
+      bool isValidIndexId(TyIndexID const & crID) const {
+        return(iv_mapFactories.find(crID) != iv_mapFactories.end());
+      }
+
+      /**
+       * returns the comparator for the index with the specidied ID.
+       * If the index has no comparator, NULL is returned.
+       */
+      uima::lowlevel::IndexComparator const * getComparator(TyIndexID const & crID) const;
+
+      /**
+       * get the kind of the index.
+       */
+      EnIndexKind getIndexKind(TyIndexID const & crID) const;
+
+      /**
+       * check if an index with ID <code>id</code> for type <code>tyType</code> exists.
+       */
+      bool isValidIndexId(TyIndexID const &, TyFSType tyType) const;
+
+      /**
+       * get the number of existing indexes.
+       */
+      size_t getNumberOfIndexes() const {
+        return iv_mapFactories.size();
+      }
+
+      /**
+       * get the most general type the index with ID <code>id</code> is defined for.
+       */
+      TyFSType getTypeForIndex(TyIndexID const & crID) const {
+        assert( isValidIndexId(crID) );
+        map<TyIndexID, TyFSType>::const_iterator cit = iv_mapIndexTypes.find(crID);
+        return (*cit).second;
+      }
+
+      uima::lowlevel::internal::IndexFactory const * getFactory(TyIndexID const & crID) const {
+        map<TyIndexID, internal::IndexFactory*>::const_iterator cit = iv_mapFactories.find(crID);
+        if (cit == iv_mapFactories.end()) {
+          return NULL;
+        }
+        return (*cit).second;
+      }
+
+      /**
+       * get the IDs of all indexes.
+       * @param rResult output parameter
+       */
+      void getAllIndexIDs(vector<TyIndexID>& rResult) const;
+
+      void reset();
+
+    };
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexdefinition.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexiterator.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexiterator.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexiterator.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexiterator.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,119 @@
+#ifndef UIMA_LOWLEVEL_INDEXITERATOR_HPP
+#define UIMA_LOWLEVEL_INDEXITERATOR_HPP
+/** \file lowlevel_indexiterator.hpp .
+-----------------------------------------------------------------------------
+
+
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp" // must be first file to be included to get pragmas
+#include "uima/lowlevel_typedefs.hpp"
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+
+    /**
+     * Abstract base class for all lowlevel iterators over indexes.
+     */
+    class UIMA_LINK_IMPORTSPEC IndexIterator {
+    public:
+
+      virtual ~IndexIterator() { }
+      /**
+       * sets the iterator to point to the first element.
+       */
+      virtual void moveToFirst() = 0;
+
+      /**
+       * advance the iterator.
+       * If <code>isValid()</code> is false, behaviour is undefined.
+       */
+      virtual void moveToNext() = 0;
+
+      virtual void moveToPrevious() = 0;
+
+      virtual void moveToLast() = 0;
+
+      /**
+       * dereference the iterator.
+       * If <code>isValid()</code> is false, behaviour is undefined.
+       */
+      virtual TyFS get() const = 0;
+
+      /**
+       * get TyFSType of the iterator.
+       * If <code>isValid()</code> is false, behaviour is undefined.
+       */
+      virtual TyFS getTyFSType() const = 0;
+
+      /**
+       * Check if the iterator points to a valid element.
+       */
+      virtual bool isValid() const = 0;
+
+      /**
+       * create a copy of this iterator.
+       */
+      virtual IndexIterator* clone() const = 0;
+
+      /**
+       * sets the iterator to the position of <code>fs</code>.
+       * @return true if <code>fs</code> is a feature structure contained in the index this
+       *         iterator iterates over and resetting was successful, false  otherwise.
+       */
+      virtual bool moveTo(TyFS fs) = 0;
+    };
+
+  }
+}
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexiterator.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexrepository.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexrepository.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexrepository.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexrepository.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,297 @@
+#ifndef UIMA_LOWLEVEL_INDEXREPOSITORY_HPP
+#define UIMA_LOWLEVEL_INDEXREPOSITORY_HPP
+/** \file indexrepository.hpp .
+-----------------------------------------------------------------------------
+
+
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+   Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+
+
+#include <map>
+#include <list>
+#include "uima/lowlevel_fsheap.hpp"
+#include "uima/lowlevel_internal_indexes.hpp"
+#include "uima/lowlevel_indexdefinition.hpp"
+#include "uima/fsindexrepository.hpp"
+#include "uima/types.h"
+#include "uima/macros.h"
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+    class IndexDefinition;
+    namespace internal {
+      class IndexFactory;
+    }
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+
+namespace uima {
+  namespace lowlevel {
+
+    /**
+     * The lowlevel index repository. Inherits from the OO API FSIndexRepository.
+     */
+    class UIMA_LINK_IMPORTSPEC IndexRepository : public FSIndexRepository {
+      friend class uima::internal::CASSerializer;
+      friend class uima::XCASWriter;
+    private:
+      IndexDefinition const & iv_indexDefinition;
+      FSHeap & iv_rFSHeap;
+      CAS & iv_cas;
+
+      // iv_indexes[t][i] is the ith index registered for type t.
+      vector<vector<internal::SingleIndex*> > iv_indexes;
+
+      // idMaximalTypeMapping[t][id] is the position of the index with id
+      //  at indexes[t]
+      vector<map<IndexDefinition::TyIndexID, size_t> > iv_idMaximalTypeMapping;
+
+      // idNonMaximalTypeIndexes[t][i] is the composite index for a nonmaximal type
+      //  with id
+      vector<map<IndexDefinition::TyIndexID, internal::CompositeIndex*> > iv_idNonMaximalTypeIndexes;
+
+      // iv_cacheDirtyFlags[t] contains all composite indexes which do
+      // not have to be updated. If a new FS of type t is added to the index
+      // iv_cacheDirtyFlags[t] is cleared.
+      vector<set<IndexABase const *> > iv_cacheDirtyFlags;
+
+      // iv_isUsed[t] indicates if index for this type has something in it
+      // iv_usedIndexes is list of indexes with something in it
+      vector<bool> iv_isUsed;
+      vector<int>  iv_usedIndexes;
+
+      //constains FSs which have been added to the IndexRepository but
+      //do not have an index definition in this CAS.
+      vector<TyFS> iv_undefinedindex;
+
+      bool iv_bIsInitialized;
+
+      IndexRepository();
+      IndexRepository(IndexRepository const &);
+      IndexRepository & operator=(IndexRepository const &);
+
+
+      void init();
+      void clearAll();
+
+      internal::SingleIndex* getSingleIndexForFS(TyFS fs, IndexDefinition::TyIndexID const & crID);
+      internal::SingleIndex* getSingleIndexForType(TyFSType tyType, IndexDefinition::TyIndexID const & crID);
+
+      vector<internal::SingleIndex*> const & getAllSingleIndexesForType(TyFSType tyType) const;
+
+      void createIndex(TyFSType t, internal::IndexFactory* fac, IndexDefinition::TyIndexID const & id, bool bIsPermanent);
+
+    protected:
+      virtual uima::lowlevel::IndexRepository & getLowlevelIndexRepository() {
+        return *this;
+      }
+
+      virtual uima::lowlevel::IndexRepository const & getLowlevelIndexRepository() const {
+        return *this;
+      }
+
+    public:
+      IndexRepository(IndexDefinition const &,
+                      uima::lowlevel::FSHeap &,
+                      CAS &);
+      ~IndexRepository();
+
+      IndexDefinition const & getIndexDefinition() const {
+        return iv_indexDefinition;
+      }
+
+      CAS & getCas() const {
+        return iv_cas;
+      }
+
+      FSHeap const & getFSHeap() const {
+        return iv_rFSHeap;
+      }
+
+      FSHeap & getFSHeap()  {
+        return iv_rFSHeap;
+      }
+
+      void getUsedIndexes(vector<TyFSType>& fillit);
+
+#ifndef NDEBUG
+      void print(ostream&) const;
+#endif
+
+      /**
+       * reset all temporary indexes.
+       */
+      void reset();
+
+      bool isInitialized() const {
+        return iv_bIsInitialized;
+      }
+
+      /**
+       * return true iff the index is up-to-date.
+       */
+      bool isDirtyForIndex(IndexABase const *) const;
+
+      /**
+       * marks the index as up-to-date.
+       */
+      void clearDirtyFlagForIndex(IndexABase const * );
+
+
+      /**
+       * reset all indexes including the index defintions.
+       * Advanced use only.
+       */
+      void resetDefinitions();
+
+
+      /**
+       * get the index with ID <code>id</code> on type <code>tyType</code>.
+       */
+      IndexABase const & getLowlevelIndex(IndexDefinition::TyIndexID const &, TyFSType tyType) const;
+
+      /**
+       * add a feature structure to all possible indexes.
+       */
+      void add(TyFS tyFS);
+
+      /**
+       * add a feature structure to the index with ID <code>id</code>.
+       */
+      void add(TyFS tyFS, IndexDefinition::TyIndexID const &);
+
+      /**
+       * removes a feature structure to all possible indexes.
+       */
+      void remove(TyFS tyFS);
+
+      /**
+       * removes a feature structure to the index with ID <code>id</code>.
+       */
+      void remove(TyFS tyFS, IndexDefinition::TyIndexID const &);
+
+      /**
+       * check if the specified FS is in some index.
+       */
+      bool contains(TyFS) const;
+
+    };
+
+  }
+}
+
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+
+    inline internal::SingleIndex* IndexRepository::getSingleIndexForType(TyFSType tyType, IndexDefinition::TyIndexID const & crID) {
+      assert( iv_bIsInitialized );
+      assert( tyType < iv_idMaximalTypeMapping.size() );
+      map<IndexDefinition::TyIndexID, size_t> const & aMap = iv_idMaximalTypeMapping[tyType];
+      map<IndexDefinition::TyIndexID, size_t>::const_iterator it = aMap.find(crID);
+      assert( it != iv_idMaximalTypeMapping[tyType].end() );
+      size_t idIndex = (*it).second;
+      assert( idIndex < iv_indexes[tyType].size() );
+      return iv_indexes[tyType][idIndex];
+    }
+
+
+    inline internal::SingleIndex* IndexRepository::getSingleIndexForFS(TyFS fs, IndexDefinition::TyIndexID const & crID) {
+      assert( iv_bIsInitialized );
+      TyFSType type = iv_rFSHeap.getType(fs);
+      return getSingleIndexForType(type, crID);
+    }
+
+    inline vector<internal::SingleIndex*> const & IndexRepository::getAllSingleIndexesForType(TyFSType tyType) const {
+      assert( iv_bIsInitialized );
+      assert( tyType < iv_idMaximalTypeMapping.size() );
+      assert( iv_rFSHeap.getTypeSystem().isValidType(tyType) );
+      return iv_indexes[tyType];
+    }
+
+
+    inline void IndexRepository::remove(TyFS fs) {
+      assert( iv_bIsInitialized );
+      TyFSType type = iv_rFSHeap.getType(fs);
+      UIMA_TPRINT("Removing fs of type " << iv_rFSHeap.getTypeSystem().getTypeName(type) << ": " << (int) fs);
+      assert( type < iv_indexes.size() );
+      vector<internal::SingleIndex*>& typeIndexes = iv_indexes[type];
+
+      vector<internal::SingleIndex*>::iterator it;
+      for (it = typeIndexes.begin(); it != typeIndexes.end(); ++it) {
+        assert( (*it)->getType() == type );
+        (*it)->remove(fs);
+      }
+    }
+
+
+    inline void IndexRepository::add(TyFS fs, IndexDefinition::TyIndexID const & crID) {
+      assert( iv_bIsInitialized );
+      internal::SingleIndex* ix = getSingleIndexForFS(fs, crID);
+      ix->add(fs);
+    }
+
+    inline void IndexRepository::remove(TyFS fs, IndexDefinition::TyIndexID const & crID) {
+      assert( iv_bIsInitialized );
+      internal::SingleIndex* ix = getSingleIndexForFS(fs, crID);
+      ix->remove(fs);
+    }
+
+
+
+  }
+}
+/* ----------------------------------------------------------------------- */
+
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_indexrepository.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_internal_heap.hpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_internal_heap.hpp?view=auto&rev=503249
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_internal_heap.hpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_internal_heap.hpp Sat Feb  3 08:54:50 2007
@@ -0,0 +1,335 @@
+#ifndef UIMA_LOWLEVEL_HEAP_HPP
+#define UIMA_LOWLEVEL_HEAP_HPP
+/** \file lowlevel_heap.hpp .
+-----------------------------------------------------------------------------
+
+
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+   Description: Base Heap design. 32-bit heaps used for interop
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/*       Include dependencies                                              */
+/* ----------------------------------------------------------------------- */
+#include "uima/pragmas.hpp"
+
+#include "uima/lowlevel_typedefs.hpp"
+
+#include "uima/macros.h"
+
+#include <vector>
+
+#if defined( _MSC_VER )
+#pragma warning( push )
+#pragma warning( disable : 4311 )
+#pragma warning( disable : 4312 )
+#endif
+
+/* ----------------------------------------------------------------------- */
+/*       Constants                                                         */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/*       Forward declarations                                              */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+  namespace internal {
+    class CASSerializer;
+    class CASDeserializer;
+  }
+}
+/* ----------------------------------------------------------------------- */
+/*       Types / Classes                                                   */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+  namespace lowlevel {
+    namespace internal {
+
+      /**
+       * Generic implementation of a possibly segmented heap of cells of type T.
+       * Used in uima::lowlevel::FSHeap for the FS heap, the StringRef Heap,
+       * and the String heap. T must be an integral type.
+       */
+      template <class T>
+      class UIMA_LINK_IMPORTSPEC Heap {
+        friend class uima::internal::CASSerializer;
+        friend class uima::internal::CASDeserializer;
+#if defined(__GNUC__) && (__GNUC__ < 3)
+        //Older GNU compiler can't handle friend properly so we make public
+      public:
+#else
+      private:
+#endif
+        // start of the current heap segment
+        T* iv_pTHeap;
+        // current top of heap
+        T* iv_pTTopOfHeap;
+        // end of current allocated heap segment
+        T* iv_pTLastHeapCell;
+        // all starts of all used segments so far (most recently allocated first)
+        vector<T*> iv_vecUsedSegments;
+        // all ends of all used segments so far (most recently allocated first)
+        vector<T*> iv_vecUsedSegmentEnds;
+        // all tops of all used segments so far (most recently allocated first)
+        vector<T*> iv_vecUsedSegmentTops;
+
+        // next available cell on heap
+        WORD32 iv_topOfHeap;
+        // segment size
+        WORD32 iv_uiCellNumber;
+        // default value of the heap cells
+        int iv_iDefaultValue;
+
+#ifdef BYEBYEPTRS
+        /**
+         * returns -1 if t lies in the current heap, an index >=0 into
+         * usedSegments, if t resides there, or -2 if t could not be found at all.
+         */
+        int searchIndex(T* t) const {
+          if ( (t >= iv_pTHeap) && (t < iv_pTTopOfHeap) ) {
+            return -1;
+          }
+          WORD32 i;
+          for (i=0; i<iv_vecUsedSegments.size(); ++i) {
+            if ( (t>=iv_vecUsedSegments[i]) && (t< iv_vecUsedSegmentEnds[i] ) ) {
+              return(int) i;
+            }
+          }
+          return -2;
+        }
+#endif
+
+      public:
+        Heap(WORD32 cells, int value)
+            : iv_pTHeap(NULL),
+            iv_pTTopOfHeap(NULL),
+            iv_pTLastHeapCell(NULL),
+            iv_uiCellNumber(cells),
+            iv_iDefaultValue(value) {
+          iv_pTHeap = new T[iv_uiCellNumber];
+          iv_topOfHeap = 1; // leave 0th cell empty
+          memset(iv_pTHeap, iv_iDefaultValue, (iv_uiCellNumber * sizeof(T)) );
+        }
+
+
+        ~Heap() {
+          if (iv_pTHeap != NULL) {
+            assert( EXISTS(iv_pTHeap) );
+            delete[] iv_pTHeap;
+          }
+          iv_pTHeap = NULL;
+        }
+
+
+        bool debugIsValidHeapCell(TyFS cell) const {
+          if ( cell < 1 || cell >= iv_topOfHeap ) {
+            return false;
+          }
+          return true;
+        }
+
+        T* getHeapStart() const {
+          return iv_pTHeap;
+        }
+        WORD32 getTopOfHeap() const {
+          return iv_topOfHeap;
+        }
+        WORD32 getLastHeapCell() const {
+          return iv_uiCellNumber;
+        }
+
+        T getHeapValue(TyFS tyFS) const {
+          return iv_pTHeap[tyFS];
+        }
+
+        void setHeapValue(TyFS tyFS, T t) {
+          iv_pTHeap[tyFS] = t;
+        }
+
+
+        /**
+         * reserve n more heap cells; if necessary, increase heap size
+         */
+        int increaseHeap(WORD32 n) {
+          //assert( n > 0 );
+          int result = iv_topOfHeap;
+          iv_topOfHeap += n;
+
+          // usual case, just return
+          if ( iv_topOfHeap < iv_uiCellNumber ) {
+            return result;
+          }
+
+          // calculate new heap size to be at least double current size
+          if ( n > iv_uiCellNumber ) {
+            iv_uiCellNumber += n;
+          } else {
+            iv_uiCellNumber *= 2;
+          }
+          T* iv_pTHeapNew = new T[iv_uiCellNumber];
+          assert( iv_pTHeapNew != NULL );
+          memcpy(iv_pTHeapNew, iv_pTHeap, result*sizeof(T));
+          memset(iv_pTHeapNew + result, iv_iDefaultValue, (iv_uiCellNumber - result)*sizeof(T));
+          delete[] iv_pTHeap;
+          iv_pTHeap = iv_pTHeapNew;
+          return result;
+        }
+
+        /**
+         * reset this heap. Paint over used cells.
+         */
+        void reset() {
+          UIMA_TPRINT("resetting heap");
+          if ( iv_topOfHeap == 1 ) {
+            // nothing to be done
+            return;
+          }
+          // !TODO don't need to fill all heaps with default value?????
+          memset(iv_pTHeap, iv_iDefaultValue, iv_topOfHeap * sizeof(T) );
+          iv_topOfHeap = 1;
+          UIMA_TPRINT("  heap reset'd");
+        }
+
+        bool resides(TyFS t) const {
+          return debugIsValidHeapCell(t);
+        }
+
+#ifdef BYEBYEPTRS
+        WORD32 getPageSize() const {
+          return iv_uiCellNumber;
+        }
+
+        WORD32 getSegmentNumber() const {
+          assert( iv_vecUsedSegments.size() == iv_vecUsedSegmentEnds.size() );
+          return iv_vecUsedSegmentEnds.size() + 1;
+        }
+
+        /**
+         * method used during serialization.
+         * sets the output parameter to a vector of pairs of pointers to
+         * the start and end, respectively, of the used heap segments
+         * in the order they were allocated.
+         */
+        void getHeapSegments( vector<pair<T*, T*> >& rvecResult ) const {
+          assert( iv_vecUsedSegments.size() == iv_vecUsedSegmentEnds.size() );
+          WORD32 uiSegmentNum = iv_vecUsedSegmentEnds.size() + 1;
+          rvecResult.resize(uiSegmentNum);
+          if (uiSegmentNum == 1) {
+            rvecResult[0] = pair<T*, T*>(iv_pTHeap, iv_pTTopOfHeap);
+            return;
+          }
+          // fill result from back to front
+          rvecResult[uiSegmentNum-1] = pair<T*, T*>(iv_pTHeap, iv_pTTopOfHeap);
+          int i;
+          for (i=uiSegmentNum-2; i>=1; --i) {
+            rvecResult[i] = pair<T*, T*>(iv_vecUsedSegments[i], iv_vecUsedSegmentEnds[i]);
+          }
+          assert( i == 0 );
+          rvecResult[0] = pair<T*, T*>(iv_vecUsedSegments[0], iv_vecUsedSegmentEnds[0]);
+        }
+
+        /**
+         * method used during DEserialization.
+         * sets the output parameter to a vector of pairs of pointers to
+         * the start and TOP, respectively, of the used heap segments
+         * in the order they were allocated.
+         */
+        void getHeapSegmentBounds( vector<pair<T*, T*> >& rvecResult ) const {
+          assert( iv_vecUsedSegments.size() == iv_vecUsedSegmentEnds.size() );
+          WORD32 uiSegmentNum = iv_vecUsedSegmentEnds.size() + 1;
+          rvecResult.resize(uiSegmentNum);
+          if (uiSegmentNum == 1) {
+            rvecResult[0] = pair<T*, T*>(iv_pTHeap, iv_pTLastHeapCell);
+            return;
+          }
+          // fill result from back to front
+          rvecResult[uiSegmentNum-1] = pair<T*, T*>(iv_pTHeap, iv_pTLastHeapCell);
+          int i;
+          for (i=uiSegmentNum-2; i>=1; --i) {
+            rvecResult[i] = pair<T*, T*>(iv_vecUsedSegments[i], iv_vecUsedSegmentTops[i]);
+          }
+          assert( i == 0 );
+          rvecResult[0] = pair<T*, T*>(iv_vecUsedSegments[0], iv_vecUsedSegmentTops[0]);
+        }
+
+        /**
+         * get a unique ID for a pointer into the heap.
+         */
+        ptrdiff_t getUniqueID(T const * t) const {
+          if (iv_vecUsedSegmentEnds.size() == 0) {
+            if ( (t > iv_pTHeap) && (t < iv_pTTopOfHeap) ) {
+              return(t - iv_pTHeap);
+            }
+          } else {
+            // if in the first allocated segment
+            if ( (t>iv_vecUsedSegments[0]) && (t< iv_vecUsedSegmentEnds[0] ) ) {
+              return(t - iv_vecUsedSegments[0]);
+            }
+            // keep absolute number of heap cells
+            WORD32 uiAbsoluteHeapCellNum = iv_vecUsedSegmentEnds[0] - iv_vecUsedSegments[0];
+            WORD32 i;
+            WORD32 len = iv_vecUsedSegments.size();
+            // for each allocated heap segment
+            for (i=1; i<len; ++i) {
+              T* segmentStart = iv_vecUsedSegments[i];
+              T* segmentEnd = iv_vecUsedSegmentEnds[i];
+              if ( (t>segmentStart) && (t< segmentEnd ) ) {
+                return uiAbsoluteHeapCellNum - 1 + (t - segmentStart);
+              }
+              uiAbsoluteHeapCellNum += (segmentEnd - segmentStart) - 1;
+            }
+            // if in the current (most recently allocated) heap segment
+            if ( (t > iv_pTHeap) && (t < iv_pTTopOfHeap) ) {
+              return uiAbsoluteHeapCellNum + (t - iv_pTHeap) - 1;
+            }
+          }
+          // if we arrived here, something went wrong
+          assert(false);
+          return -1;
+        }
+#endif
+      };
+
+    }
+  }
+}
+
+/* ----------------------------------------------------------------------- */
+/*       Implementation                                                    */
+/* ----------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+
+#if defined( _MSC_VER )
+#pragma warning( pop )
+#endif
+
+#endif
+

Propchange: incubator/uima/uimacpp/trunk/src/cas/uima/lowlevel_internal_heap.hpp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message