You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/02/03 17:54:11 UTC
svn commit: r503248 [4/8] - /incubator/uima/uimacpp/trunk/src/cas/
Added: incubator/uima/uimacpp/trunk/src/cas/internal_serializedcas.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/internal_serializedcas.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/internal_serializedcas.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/internal_serializedcas.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,210 @@
+/** \file internal_serializedcas.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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/internal_serializedcas.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+ namespace internal {
+
+//!TODO check this default size, particularly for blob-based data serialization
+ SerializedCAS::SerializedCAS()
+ : iv_stringHeap(10000, 0) {}
+
+ SerializedCAS::~SerializedCAS() {}
+
+
+ void SerializedCAS::reset() {
+ iv_stringHeap.reset();
+
+ iv_ulstrDocument = UnicodeStringRef();
+
+ iv_vecTypeInheritanceTable.clear();
+ iv_vecFeatureDefinitionTable.clear();
+ iv_vecTypeSymbolTable.clear();
+ iv_vecFeatureSymbolTable.clear();
+ iv_vecFeatureOffsetTable.clear();
+ iv_vecTypePriorityTable.clear();
+
+ iv_vecIndexIDTable.clear();
+ iv_vecComparatorDefinitionTable.clear();
+ iv_vecComparatorStartTable.clear();
+ iv_vecIndexKindTable.clear();
+
+ iv_vecFSHeapArray.clear();
+ iv_vecByteHeapArray.clear();
+ iv_vecShortHeapArray.clear();
+ iv_vecLongHeapArray.clear();
+
+
+ iv_vecStringSymbolTable.clear();
+
+ iv_vecIndexedFSs.clear();
+ }
+
+
+// cout << of a 64bit type causes a warning (conversion to int, loss of data)
+// since we can't help the implementation of cout we surpress the warning
+#if defined( _MSC_VER )
+#pragma warning( push )
+#pragma warning( disable : 4244 )
+#endif
+ template <class T>
+ void printVector(ostream & os, vector<T> const & vec) {
+ size_t i;
+ for (i=0; i<vec.size(); ++i) {
+ os << i << ": " << vec[i] << endl;
+ }
+ }
+#if defined( _MSC_VER )
+#pragma warning( pop )
+#endif
+
+
+
+
+// cout << of a 64bit type causes a warning (conversion to int, loss of data)
+// since we can't help the implementation of cout we surpress the warning
+#if defined( _MSC_VER )
+#pragma warning( push )
+#pragma warning( disable : 4244 )
+#endif
+ void SerializedCAS::print(ostream & os) const {
+
+ os << "===============================" << endl;
+ os << "Document:" << endl;
+ os << getDocument() << endl;
+
+ os << endl << "===============================" << endl;
+ os << "Type Inheritance: " << endl;
+ vector<TyNum> const & typeInh = getTypeInheritanceTable();
+ printVector(os, typeInh);
+
+ os << "Type Symbol Table: " << endl;
+ printVector(os, getTypeSymbolTable());
+
+ os << "Feature Definition: " << endl;
+ printVector(os, getFeatureDefinitionTable());
+
+ os << "Feature Symbol Table: " << endl;
+ printVector(os, getFeatureSymbolTable());
+
+ os << "Feature offsets:" << endl;
+ printVector(os, getFeatureOffsetTable());
+
+ os << "Index IDs:" << endl;
+ printVector(os, getIndexIDTable() );
+
+ os << "Comparator start:" << endl;
+ printVector(os, getComparatorStartTable() );
+
+ os << "Comparatordefinition:" << endl;
+ printVector(os, getComparatorDefinitionTable());
+
+ os << "IndexKind:" << endl;
+ printVector(os, getIndexKindTable());
+
+
+ os << endl << "===============================" << endl;
+ os << "Serialized Heap:" << endl;
+ vector<TyNum> const & heap = getFSHeapArray();
+ size_t i;
+ for (i=0; i<heap.size(); ++i) {
+ os << i << ": " << heap[i] << endl;
+ }
+
+ os << endl << "===============================" << endl;
+ os << "Serialized ByteHeap:" << endl;
+ vector<char> const & bheap = getByteHeapArray();
+
+ for (i=0; i<bheap.size(); ++i) {
+ os << i << ": " << bheap[i] << endl;
+ }
+
+ os << endl << "===============================" << endl;
+ os << "Serialized ShortHeap:" << endl;
+ vector<short> const & sheap = getShortHeapArray();
+
+ for (i=0; i<sheap.size(); ++i) {
+ os << i << ": " << sheap[i] << endl;
+ }
+ os << endl << "===============================" << endl;
+ os << "Serialized LongHeap:" << endl;
+ vector<INT64> const & lheap = getLongHeapArray();
+
+ for (i=0; i<lheap.size(); ++i) {
+ os << i << ": " << lheap[i] << endl;
+ }
+
+ os << endl << "===============================" << endl;
+ os << "Serialized String table:" << endl;
+ vector<UnicodeStringRef> const & strings = getStringSymbolTable();
+ for (i=0; i<strings.size(); ++i) {
+ os << i << ": " << strings[i] << endl;
+ }
+
+ os << endl << "===============================" << endl;
+ os << "Indexed FSs:" << endl;
+ vector<TyNum> const & indexedFSs = getIndexedFSs();
+ for (i=0; i<indexedFSs.size(); ++i) {
+ os << i << ": " << indexedFSs[i] << endl;
+ }
+ }
+#if defined( _MSC_VER )
+#pragma warning( pop )
+#endif
+
+ }
+}
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/internal_serializedcas.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/internal_typeshortcuts.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/internal_typeshortcuts.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/internal_typeshortcuts.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/internal_typeshortcuts.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,157 @@
+/** \file internal_typeshortcuts.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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/internal_typeshortcuts.hpp"
+#include "uima/lowlevel_typesystem.hpp"
+#include "uima/typesystem.hpp"
+#include "uima/cas.hpp"
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+ namespace internal {
+ bool areTypeShortcutsCorrect(uima::lowlevel::TypeSystem const & crTypeSystem) {
+ bool bResult = true;
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_INTEGER) == gs_tyIntegerType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_FLOAT) == gs_tyFloatType);
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_STRING) == gs_tyStringType);
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_ARRAY_BASE) == gs_tyArrayBaseType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_FS_ARRAY) == gs_tyFSArrayType);
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_LIST_BASE) == gs_tyListBaseType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_FS_LIST) == gs_tyFSListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_EMPTY_FS_LIST) == gs_tyEListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_NON_EMPTY_FS_LIST) == gs_tyNEListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEListType, CAS::FEATURE_BASE_NAME_HEAD) == gs_tyHeadFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEListType, CAS::FEATURE_BASE_NAME_TAIL) == gs_tyTailFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEListType, gs_tyHeadFeature ) );
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEListType, gs_tyTailFeature ) );
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_FLOAT_LIST) == gs_tyFloatListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_EMPTY_FLOAT_LIST) == gs_tyEFloatListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_NON_EMPTY_FLOAT_LIST) == gs_tyNEFloatListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEFloatListType, CAS::FEATURE_BASE_NAME_HEAD) == gs_tyFloatHeadFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEFloatListType, CAS::FEATURE_BASE_NAME_TAIL) == gs_tyFloatTailFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEFloatListType, gs_tyFloatHeadFeature ) );
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEFloatListType, gs_tyFloatTailFeature ) );
+ assert( bResult );
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_INTEGER_LIST) == gs_tyIntListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_EMPTY_INTEGER_LIST) == gs_tyEIntListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_NON_EMPTY_INTEGER_LIST) == gs_tyNEIntListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEIntListType, CAS::FEATURE_BASE_NAME_HEAD) == gs_tyIntHeadFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEIntListType, CAS::FEATURE_BASE_NAME_TAIL) == gs_tyIntTailFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEIntListType, gs_tyIntHeadFeature ) );
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEIntListType, gs_tyIntTailFeature ) );
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_STRING_LIST) == gs_tyStringListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_NON_EMPTY_STRING_LIST) == gs_tyNEStringListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_EMPTY_STRING_LIST) == gs_tyEStringListType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEStringListType, CAS::FEATURE_BASE_NAME_HEAD) == gs_tyStringHeadFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyNEStringListType, CAS::FEATURE_BASE_NAME_TAIL) == gs_tyStringTailFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEStringListType, gs_tyStringHeadFeature ) );
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyNEStringListType, gs_tyStringTailFeature ) );
+ assert( bResult );
+
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_ANNOTATION_BASE) == gs_tyAnnotationBaseType);
+ bResult = bResult && (crTypeSystem.getTypeByName(CAS::TYPE_NAME_ANNOTATION) == gs_tyAnnotationType);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyAnnotationType, uima::CAS::FEATURE_BASE_NAME_BEGIN) == gs_tyBeginPosFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyAnnotationType, gs_tyBeginPosFeature ) );
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.getFeatureByBaseName(gs_tyAnnotationType, uima::CAS::FEATURE_BASE_NAME_END) == gs_tyEndPosFeature);
+ assert( bResult );
+ bResult = bResult && (crTypeSystem.isAppropriateFeature( gs_tyAnnotationType, gs_tyEndPosFeature ) );
+ assert( bResult );
+
+ //TODO:: upadate for new primitive types and update for Sofa , AnnotatioBase types
+ return bResult;
+ }
+ }
+}
+
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/internal_typeshortcuts.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/internal_xmlconstants.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/internal_xmlconstants.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/internal_xmlconstants.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/internal_xmlconstants.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,67 @@
+/** \file internal_xmlconstants.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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/internal_xmlconstants.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+ namespace internal {
+ char const * XMLConstants::TAGNAME_TYPE = "type";
+ char const * XMLConstants::TAGNAME_FEATURE = "feature";
+ char const * XMLConstants::TAGNAME_TYPEHIERARCHY = "type_system";
+ char const * XMLConstants::ATTRIBUTENAME_RANGE = "range";
+ char const * XMLConstants::ATTRIBUTENAME_NAME = "name";
+ }
+}
+
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/internal_xmlconstants.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/listfs.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/listfs.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/listfs.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/listfs.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,653 @@
+/** \file listfs.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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/listfs.hpp"
+#include "uima/featurestructure.hpp"
+#include "uima/lowlevel_fsheap.hpp"
+#include "uima/msg.h"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/internal_typeshortcuts.hpp"
+#include "uima/internal_fsvalue_accessors.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+ /* ----------------------------------------------------------------------- */
+ /* Exceptions Implementation */
+ /* ----------------------------------------------------------------------- */
+ UIMA_EXC_CLASSIMPLEMENT(FSIsNotListException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(ListIsEmptyException, CASException);
+ UIMA_EXC_CLASSIMPLEMENT(ListIsCircularException, CASException);
+
+ /* ----------------------------------------------------------------------- */
+ /* Tool Functions Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ checkList(lowlevel::TyFS tyFS, TyMessageId tyContext) const {
+ assert(EXISTS(iv_cas));
+ lowlevel::TyFSType tyType = iv_cas->getHeap()->getType( tyFS );
+ if ( ! iv_cas->getHeap()->getTypeSystem().subsumes( LIST_TYPE, tyType) ) {
+ UIMA_EXC_THROW_NEW(FSIsNotListException,
+ UIMA_ERR_FS_IS_NOT_LIST,
+ UIMA_MSG_ID_EXC_FS_IS_NOT_LIST,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ checkNEList(lowlevel::TyFS tyFS, TyMessageId tyContext) const {
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ lowlevel::TyFSType tyType = crHeap.getType( tyFS );
+ if (tyType != NELIST_TYPE) {
+ UIMA_EXC_THROW_NEW(ListIsEmptyException,
+ UIMA_ERR_LIST_IS_EMPTY,
+ UIMA_MSG_ID_EXC_LIST_IS_EMPTY,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable);
+ }
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ checkCircularity(lowlevel::TyFS tyFS1, lowlevel::TyFS tyFS2, TyMessageId tyContext) const {
+ assert(EXISTS(iv_cas));
+ if ( tyFS1 == tyFS2 ) {
+ lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ lowlevel::TyFSType tyType1 = crHeap.getType( tyFS1 );
+ lowlevel::TyFSType tyType2 = crHeap.getType( tyFS2 );
+ // if both lists are empty we don't have any problem
+ if ( tyType1 == ELIST_TYPE
+ && tyType2 == ELIST_TYPE) {
+ return;
+ }
+ UIMA_EXC_THROW_NEW(ListIsCircularException,
+ UIMA_ERR_LIST_IS_CIRCULAR,
+ UIMA_MSG_ID_EXC_LIST_IS_CIRCULAR,
+ ErrorMessage(tyContext),
+ ErrorInfo::recoverable
+ );
+ }
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ lowlevel::TyFS
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ getLastListElement(lowlevel::TyFS tyListFS, size_t & rOutSize) const {
+ assert(EXISTS(iv_cas));
+ rOutSize = 0;
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ assert( rHeap.getType(tyListFS) == NELIST_TYPE );
+ lowlevel::TyFS tyCurrentList = tyListFS;
+ while (true) {
+ assert( rHeap.getType(tyCurrentList) == NELIST_TYPE );
+ lowlevel::TyFS tyNextList = rHeap.getFSValue(tyCurrentList, TAIL_FEATURE);
+ if ( rHeap.getType(tyNextList) != NELIST_TYPE ) {
+ assert( rHeap.getType(tyNextList) == ELIST_TYPE );
+ break;
+ }
+ tyCurrentList = tyNextList;
+ ++rOutSize;
+ }
+ return tyCurrentList;
+ }
+
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ lowlevel::TyFS
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ addLastLowlevel(lowlevel::TyFS tyListFS, T tyNewElement) {
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ assert( rHeap.getType(tyListFS) == NELIST_TYPE );
+ size_t ui = 0;
+ lowlevel::TyFS tyLastListElement = getLastListElement(tyListFS, ui);
+
+ lowlevel::TyFS tyEmptyList = rHeap.getFSValue( tyLastListElement, TAIL_FEATURE);
+ assert( ! rHeap.isUntouchedFSValue(tyLastListElement, TAIL_FEATURE) );
+ assert( rHeap.getType( tyEmptyList ) == ELIST_TYPE );
+
+ lowlevel::TyFS tyNewListElement = rHeap.createFS(NELIST_TYPE);
+ internal::setFSValueTempl((uima::CAS *)iv_cas, tyNewListElement, HEAD_FEATURE, tyNewElement);
+ rHeap.setFSValue( tyNewListElement, TAIL_FEATURE, tyEmptyList );
+ rHeap.setFSValue( tyLastListElement, TAIL_FEATURE, tyNewListElement );
+
+ return tyNewListElement;
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ appendLowlevel(lowlevel::TyFS tyListFS1, lowlevel::TyFS tyListFS2) {
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ assert( rHeap.getType(tyListFS1) == NELIST_TYPE );
+ size_t ui = 0;
+ lowlevel::TyFS tyLastListElement = getLastListElement(tyListFS1, ui);
+
+#ifndef NDEBUG
+ lowlevel::TyFS tyEmptyList = rHeap.getFSValue( tyLastListElement, TAIL_FEATURE);
+ assert( ! rHeap.isUntouchedFSValue(tyLastListElement, TAIL_FEATURE) );
+ assert( rHeap.getType( tyEmptyList ) == ELIST_TYPE );
+#endif /* debug mode only */
+
+ rHeap.setFSValue( tyLastListElement, TAIL_FEATURE, tyListFS2);
+ }
+ /* ----------------------------------------------------------------------- */
+ /* BasicListFS Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ BasicListFS(lowlevel::TyFS anFS, uima::CAS & cas, bool bDoChecks) :
+ FeatureStructure(anFS, cas) {
+ if (bDoChecks) {
+ checkValidity(UIMA_MSG_ID_EXCON_CREATING_LISTFS);
+ checkList(iv_tyFS, UIMA_MSG_ID_EXCON_CREATING_LISTFS);
+ }
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ BasicListFS() :
+ FeatureStructure() {}
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ BasicListFS( FeatureStructure const & fs) :
+ FeatureStructure(fs) {
+ if (isValid()) {
+ checkList(iv_tyFS, UIMA_MSG_ID_EXCON_CREATING_LISTFS);
+ }
+ // we should not have any additional members
+ assert(sizeof(BasicListFS) == sizeof(FeatureStructure));
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ bool
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ isEmpty() const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_LIST_ISEMPTY);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ lowlevel::TyFSType tyType = crHeap.getType( iv_tyFS );
+ return(tyType != NELIST_TYPE);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ size_t
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ getLength() const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_LIST_LENGTH);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap & rFSHeap = *iv_cas->getHeap();
+ if ( rFSHeap.getType( iv_tyFS ) != NELIST_TYPE ) {
+ return 0;
+ }
+ size_t uiResult = 0;
+ (void) getLastListElement(iv_tyFS, uiResult);
+ return uiResult+1;
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ T
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ getHead() const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_LIST_HEAD);
+ checkNEList(iv_tyFS, UIMA_MSG_ID_EXCON_GETTING_LIST_HEAD);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ assert( crHeap.getType(iv_tyFS) == NELIST_TYPE );
+ T result;
+ internal::getFSValueTempl((uima::CAS *)iv_cas, iv_tyFS, HEAD_FEATURE, result);
+ return result;
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ setHead( T const & fs ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_LIST_HEAD);
+ checkNEList(iv_tyFS, UIMA_MSG_ID_EXCON_SETTING_LIST_HEAD);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ assert( rHeap.getType(iv_tyFS) == NELIST_TYPE );
+ internal::setFSValueTempl((uima::CAS *)iv_cas, iv_tyFS, HEAD_FEATURE, fs);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ getTail() const {
+ checkValidity(UIMA_MSG_ID_EXCON_GETTING_LIST_TAIL);
+ checkNEList(iv_tyFS, UIMA_MSG_ID_EXCON_GETTING_LIST_TAIL);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ assert( crHeap.getType(iv_tyFS) == NELIST_TYPE );
+ lowlevel::TyFS tyNextList = crHeap.getFSValue(iv_tyFS, TAIL_FEATURE);
+ return BasicListFS(tyNextList, *iv_cas, false);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ setTail( BasicListFS fs ) {
+ checkValidity(UIMA_MSG_ID_EXCON_SETTING_LIST_TAIL);
+ fs.checkValidity(UIMA_MSG_ID_EXCON_SETTING_LIST_TAIL);
+ checkNEList(iv_tyFS, UIMA_MSG_ID_EXCON_SETTING_LIST_TAIL);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ assert( rHeap.getType(iv_tyFS) == NELIST_TYPE );
+ rHeap.setFSValue(iv_tyFS, TAIL_FEATURE, fs.iv_tyFS);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ addFirst( T const & fs ) {
+ checkValidity(UIMA_MSG_ID_EXCON_ADDING_LIST_VALUE);
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ lowlevel::TyFS tyNEFS = rHeap.createFS( NELIST_TYPE );
+ rHeap.setFSValue(tyNEFS, TAIL_FEATURE, iv_tyFS);
+ internal::setFSValueTempl((uima::CAS *)iv_cas, tyNEFS, HEAD_FEATURE, fs);
+ iv_tyFS = tyNEFS;
+ return(*this);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ addLast( T const & fs ) {
+ checkValidity(UIMA_MSG_ID_EXCON_ADDING_LIST_VALUE);
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ lowlevel::TyFS tyNewEnd;
+ if (rHeap.getType( iv_tyFS ) == NELIST_TYPE) {
+ // if this list is not empty we search for the end and put fs there
+ tyNewEnd = addLastLowlevel(iv_tyFS, fs);
+ } else {
+ // if this list is empty we create an inital terminated list
+ assert(rHeap.getType( iv_tyFS ) == ELIST_TYPE);
+ lowlevel::TyFS tyEFS = iv_tyFS;
+ iv_tyFS = rHeap.createFS( NELIST_TYPE );
+ internal::setFSValueTempl((uima::CAS *)iv_cas, iv_tyFS, HEAD_FEATURE, fs);
+ rHeap.setFSValue(iv_tyFS, TAIL_FEATURE, tyEFS);
+ tyNewEnd = iv_tyFS;
+ }
+ return BasicListFS(tyNewEnd, *iv_cas, false);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ append( BasicListFS fs ) {
+ checkValidity(UIMA_MSG_ID_EXCON_APPENDING_TO_LIST);
+ fs.checkValidity(UIMA_MSG_ID_EXCON_APPENDING_TO_LIST);
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ checkCircularity(iv_tyFS, fs.iv_tyFS, UIMA_MSG_ID_EXCON_APPENDING_TO_LIST);
+ if (rHeap.getType( iv_tyFS ) == NELIST_TYPE) {
+ // if this list is not empty we do a full append
+ appendLowlevel(iv_tyFS, fs.iv_tyFS);
+ } else {
+ // if this list is empty we just replace it with with fs
+ iv_tyFS = fs.iv_tyFS;
+ }
+ return(*this);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ prepend( BasicListFS fs ) {
+ checkValidity(UIMA_MSG_ID_EXCON_PREPENDING_TO_LIST);
+ fs.checkValidity(UIMA_MSG_ID_EXCON_PREPENDING_TO_LIST);
+ lowlevel::FSHeap & rHeap = *iv_cas->getHeap();
+ checkCircularity(iv_tyFS, fs.iv_tyFS, UIMA_MSG_ID_EXCON_PREPENDING_TO_LIST);
+ // only do something if fs does have some elements
+ if (rHeap.getType( fs.iv_tyFS ) == NELIST_TYPE) {
+ appendLowlevel(fs.iv_tyFS, iv_tyFS);
+ iv_tyFS = fs.iv_tyFS;
+ }
+ return(*this);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ moveToNext() {
+ checkValidity(UIMA_MSG_ID_EXCON_MOVING_LIST_TO_NEXT);
+ checkNEList(iv_tyFS, UIMA_MSG_ID_EXCON_MOVING_LIST_TO_NEXT);
+ assert(EXISTS(iv_cas));
+ lowlevel::FSHeap const & crHeap = *iv_cas->getHeap();
+ assert( crHeap.getType(iv_tyFS) == NELIST_TYPE );
+ lowlevel::TyFS tyNextList = crHeap.getFSValue(iv_tyFS, TAIL_FEATURE);
+ iv_tyFS = tyNextList;
+#ifndef NDEBUG
+ checkList(iv_tyFS, UIMA_MSG_ID_EXCON_MOVING_LIST_TO_NEXT);
+#endif
+ }
+
+
+ template < class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ void terminateList(BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE> & aList,
+ uima::lowlevel::FSHeap & heap) {
+ uima::lowlevel::TyFS emptyList = heap.createFS(ELIST_TYPE);
+ uima::lowlevel::TyFS tailElement = uima::internal::FSPromoter::demoteFS( aList );
+ heap.setFSValue( tailElement, TAIL_FEATURE, emptyList );
+ }
+
+
+ template < class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ deleteElementFromList(BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE> & aList,
+ uima::lowlevel::FSHeap & heap,
+ T const & element) {
+ assert(! aList.isEmpty() );
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE> tail = aList.getTail();
+ if (! tail.isEmpty() ) {
+ if (tail.getHead() == element) {
+ aList.setTail(tail.getTail());
+ terminateList(tail, heap);
+ return tail;
+ } else {
+ return deleteElementFromList(tail, heap, element);
+ }
+ }
+ return BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>();
+ }
+
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::removeElement( T const & element ) {
+ checkValidity(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT);
+ if (! isEmpty() ) {
+ // if the first element of list is to be deleted
+ if (getHead() == element) {
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE> result = *this;
+ *this = getTail();
+ terminateList(result, *iv_cas->getHeap() );
+ return result;
+ } else {
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE> result = deleteElementFromList(*this, *iv_cas->getHeap(), element);
+ return result;
+ }
+ }
+ return BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>();
+ }
+
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ /*static*/ bool
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ hasListElements(FeatureStructure fs, Feature const & f) {
+ // there are several ways a feature can have zero values
+ uima::lowlevel::FSHeap const & crHeap = *internal::FSPromoter::getFSHeap(fs);
+ lowlevel::TyFSFeature tyFeat = internal::FSPromoter::demoteFeature( f );
+ lowlevel::TyFS tyFS = internal::FSPromoter::demoteFS( fs );
+ // 1: it is untouched. So we don't touch it either and return false
+ if ( crHeap.isUntouchedFSValue(tyFS, tyFeat) ) {
+ return false;
+ }
+ lowlevel::TyFS tyFSResult = internal::FSPromoter::getFSHeap(fs)->getFSValue(tyFS, tyFeat);
+ // the value can be either
+ // 1: a generic list type (should not happen but is a valid possiblity)
+ // 2: an empty list (no elements in the list)
+ // 3: a non-empty list (some elements in the list)
+ assert( crHeap.getType( tyFSResult ) == LIST_TYPE
+ || crHeap.getType( tyFSResult ) == ELIST_TYPE
+ || crHeap.getType( tyFSResult ) == NELIST_TYPE);
+ // Return true, if the value is of type non-empty list
+ return(crHeap.getType( tyFSResult ) == NELIST_TYPE);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ /*static*/ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ getListFSValue( FeatureStructure const & fs, Feature const & f ) {
+ assert(fs.isValid());
+ uima::CAS & rCas = *internal::FSPromoter::getFSCas(fs);
+ uima::lowlevel::FSHeap & rHeap = *internal::FSPromoter::getFSHeap(fs);
+ lowlevel::TyFSFeature tyF = internal::FSPromoter::demoteFeature( f );
+ lowlevel::TyFS tyFS = internal::FSPromoter::demoteFS( fs );
+ // check range type
+ lowlevel::TyFSType tyRangeType = rHeap.getTypeSystem().getRangeType(tyF);
+ if ( ! rHeap.getTypeSystem().subsumes( LIST_TYPE, tyRangeType) ) {
+ UIMA_EXC_THROW_NEW(FSIsNotListException,
+ UIMA_ERR_FS_IS_NOT_LIST,
+ UIMA_MSG_ID_EXC_FS_IS_NOT_LIST,
+ ErrorMessage(UIMA_MSG_ID_EXCON_GETTING_FIRST_LIST_ELEMENT),
+ ErrorInfo::recoverable
+ );
+ }
+
+ // it is untouched. We have to create a proper empty terminated list
+ if ( rHeap.isUntouchedFSValue(tyFS, tyF) ) {
+ lowlevel::TyFS tyFSEList = rHeap.createFS(ELIST_TYPE);
+ rHeap.setFSValue(tyFS, tyF, tyFSEList);
+ return BasicListFS(tyFSEList, rCas);
+ }
+ return BasicListFS(rHeap.getFSValue(tyFS, tyF), rCas, false);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ /*static*/ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ createListFS( CAS & cas, bool bIsPermanent ) {
+ lowlevel::FSHeap & rHeap = *uima::internal::FSPromoter::getFSHeap(cas);
+ lowlevel::TyFS tyFS = rHeap.createFS(ELIST_TYPE);
+ return BasicListFS(tyFS, cas, false);
+ }
+
+ template< class T,
+ const uima::lowlevel::TyFSType LIST_TYPE,
+ const uima::lowlevel::TyFSType ELIST_TYPE,
+ const uima::lowlevel::TyFSType NELIST_TYPE,
+ const uima::lowlevel::TyFSFeature HEAD_FEATURE,
+ const uima::lowlevel::TyFSFeature TAIL_FEATURE >
+ /*static*/ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>
+ BasicListFS<T, LIST_TYPE, ELIST_TYPE, NELIST_TYPE, HEAD_FEATURE, TAIL_FEATURE>::
+ createListFS( CAS & cas, T const & head, bool bIsPermanent ) {
+ lowlevel::FSHeap & rHeap = *uima::internal::FSPromoter::getFSHeap(cas);
+ lowlevel::TyFS tyFS = rHeap.createFS( NELIST_TYPE );
+ lowlevel::TyFS tyEFS = rHeap.createFS( ELIST_TYPE );
+ internal::setFSValueTempl(&cas, tyFS, HEAD_FEATURE, head);
+ rHeap.setFSValue(tyFS, TAIL_FEATURE, tyEFS);
+ return BasicListFS(tyFS, cas, false);
+ }
+
+ // explicit instantiation
+ template class BasicListFS< FeatureStructure, internal::gs_tyFSListType, internal::gs_tyEListType, internal::gs_tyNEListType, internal::gs_tyHeadFeature, internal::gs_tyTailFeature >;
+ // explicit instantiation
+ template class BasicListFS< float, internal::gs_tyFloatListType, internal::gs_tyEFloatListType, internal::gs_tyNEFloatListType, internal::gs_tyFloatHeadFeature, internal::gs_tyFloatTailFeature >;
+ // explicit instantiation
+ template class BasicListFS< int, internal::gs_tyIntListType, internal::gs_tyEIntListType, internal::gs_tyNEIntListType, internal::gs_tyIntHeadFeature, internal::gs_tyIntTailFeature >;
+ // explicit instantiation
+ template class BasicListFS< UnicodeStringRef, internal::gs_tyStringListType, internal::gs_tyEStringListType, internal::gs_tyNEStringListType, internal::gs_tyStringHeadFeature, internal::gs_tyStringTailFeature >;
+
+} // namespace uima
+
+/* ----------------------------------------------------------------------- */
+/* <EOF> */
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/listfs.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/lowlevel_fsheap.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/lowlevel_fsheap.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/lowlevel_fsheap.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/lowlevel_fsheap.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,355 @@
+/** \file lowlevel_fsheap.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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"
+
+//#define DEBUG_VERBOSE
+#include "uima/macros.h"
+
+#include "uima/lowlevel_fsheap.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+
+ namespace lowlevel {
+
+ TyFS const FSHeap::INVALID_FS = 0;
+
+ FSHeap::FSHeap(TypeSystem const & rclTypeSystem,
+ size_t uiFSHeapPageSize,
+ size_t uiStringHeapPageSize,
+ size_t uiStringRefHeapPageSize) :
+ iv_clTemporaryHeap(uiFSHeapPageSize, 0),
+ iv_clTemporaryStringHeap(uiStringHeapPageSize, 0),
+ iv_clTemporaryStringRefHeap(uiStringRefHeapPageSize, 0),
+ iv_clTemporary8BitHeap(1, 0),
+ iv_clTemporary16BitHeap(1, 0),
+ iv_clTemporary64BitHeap(1, 0),
+ iv_rclTypeSystem(rclTypeSystem) {
+ UIMA_TPRINT("heap constructed");
+ assert( INVALID_FS == 0 );
+ }
+
+ FSHeap::FSHeap(TypeSystem const & rclTypeSystem,
+ size_t uiFSHeapPageSize,
+ size_t uiStringHeapPageSize,
+ size_t uiStringRefHeapPageSize,
+ size_t uiMinHeapPageSize) :
+ iv_clTemporaryHeap(uiFSHeapPageSize, 0),
+ iv_clTemporaryStringHeap(uiStringHeapPageSize, 0),
+ iv_clTemporaryStringRefHeap(uiStringRefHeapPageSize, 0),
+ iv_clTemporary8BitHeap(uiMinHeapPageSize, 0),
+ iv_clTemporary16BitHeap(uiMinHeapPageSize, 0),
+ iv_clTemporary64BitHeap(uiMinHeapPageSize, 0),
+ iv_rclTypeSystem(rclTypeSystem) {
+ UIMA_TPRINT("heap constructed");
+ assert( INVALID_FS == 0 );
+ }
+
+
+ FSHeap::~FSHeap() {}
+
+ void FSHeap::reset() {
+ assert( debugIsConsistent() );
+ TyFSHeap & rHeapToBeResetted = getHeap();
+ rHeapToBeResetted.reset();
+ TyStringHeap & rStringHeapToBeResetted = getStringHeap();
+ rStringHeapToBeResetted.reset();
+ TyStringRefHeap & rStringRefHeapToBeResetted = getStringRefHeap();
+ rStringRefHeapToBeResetted.reset();
+
+ Ty8BitHeap & r8BitHeapToBeResetted = get8BitHeap();
+ r8BitHeapToBeResetted.reset();
+ Ty16BitHeap & r16BitHeapToBeResetted = get16BitHeap();
+ r16BitHeapToBeResetted.reset();
+ Ty64BitHeap & r64BitHeapToBeResetted = get64BitHeap();
+ r64BitHeapToBeResetted.reset();
+ }
+
+
+ void FSHeap::setStringValue(TyFS tyFs, TyFSFeature tyFeature, int strRef) {
+ assert( iv_rclTypeSystem.isValidFeature(tyFeature) );
+ assert( iv_rclTypeSystem.subsumes(uima::internal::gs_tyStringType, iv_rclTypeSystem.getRangeType(tyFeature)));
+
+#ifndef NDEBUG
+ TyFSType rangeType = iv_rclTypeSystem.getRangeType(tyFeature);
+ // if we have an enumeration subtype of string
+ if (rangeType != uima::internal::gs_tyStringType ) {
+ vector<icu::UnicodeString> const & crStringSet = iv_rclTypeSystem.getStringsForStringSubtype(rangeType);
+ vector<icu::UnicodeString>::const_iterator cit;
+ bool bStringFound = false;
+ UnicodeStringRef crStringRef(iv_clTemporaryStringHeap.getHeapStart()+strRef);
+ for (cit = crStringSet.begin(); cit != crStringSet.end(); ++cit) {
+ UnicodeStringRef ref(*cit);
+ if ( ref == crStringRef ) {
+ bStringFound = true;
+ break;
+ }
+ }
+ assert (bStringFound);
+ }
+#endif
+
+ TyFS tyCurrentString = getFeatureInternal( tyFs, tyFeature );
+ if (tyCurrentString == 0) {
+ // add entry to StringRefHeap and set values there
+ tyCurrentString = getStringAsFS(strRef);
+ } else {
+ // reuse entry in StringRefHeap
+ setStringRef(tyCurrentString, strRef);
+ }
+
+ setFeatureInternal(tyFs, tyFeature, tyCurrentString);
+ }
+
+ void FSHeap::copyFeatures(TyFS tyTarget, TyFS tySource, size_t featNum) {
+ uima::lowlevel::TyFSType type = getType(tyTarget);
+ if (featNum == 0) {
+ assert( type == getType(tySource) );
+ featNum = iv_rclTypeSystem.getFeatureNumber( getType(tyTarget));
+ }
+ size_t i;
+ for (i=1; i<=featNum; ++i) {
+ uima::lowlevel::TyFSFeature feat = iv_rclTypeSystem.getFeatureFromOffset(type, i);
+ if ( iv_rclTypeSystem.subsumes( uima::internal::gs_tyStringType, iv_rclTypeSystem.getRangeType(feat) ) ) {
+ // get offset of stringRef in stringRefHeap
+ int strRef = iv_clTemporaryHeap.getHeapValue(tySource+i);
+ // if string value set, create duplicate reference to string in refHeap
+ if (strRef != 0) {
+ int ref = iv_clTemporaryStringRefHeap.getHeapValue(1 + 2*(strRef-1));
+ iv_clTemporaryHeap.setHeapValue(tyTarget+i, getStringAsFS(ref));
+ }
+ } else {
+ iv_clTemporaryHeap.setHeapValue(tyTarget+i, iv_clTemporaryHeap.getHeapValue(tySource+i));
+ }
+ }
+
+ }
+
+
+
+// cout << of a 64bit type causes a warning (conversion to int, loss of data)
+// since we can't help the implementation of cout we surpress the warning
+#if defined( _MSC_VER )
+#pragma warning( push )
+#pragma warning( disable : 4244 )
+#endif
+ void FSHeap::printFS(ostream& os, TyFS fs) const {
+ TyFSType type = getType( fs );
+ icu::UnicodeString typeName = iv_rclTypeSystem.getTypeName(type);
+ int n=0;
+ os << n++ << ": | " << typeName << endl;
+ unsigned int i;
+ for (i=1; i<iv_rclTypeSystem.getFeatureNumber(type) + 1; ++i) {
+ os << n++ << ": | " << (ptrdiff_t) getFeatureWithOffset(fs, i) << endl;
+ }
+ }
+
+
+ void FSHeap::print(ostream& os) const {
+ os << "=============================================" << endl;
+#ifdef BYEBYEPTRS
+ void * h;
+ size_t i;
+ size_t lastHeapCell = iv_clTemporaryHeap.getLastHeapCell();
+ size_t topOfHeap = iv_clTemporaryHeap.getTopOfHeap();
+
+ if (true) {
+ os << "Plain HEAP:" << endl;
+ h=iv_clTemporaryHeap.getHeapStart();
+ i=0;
+ for (h=1; h< lastHeapCell; ++h) {
+ os << i++ << " (" << (ptrdiff_t) h << ", " << h << ") : | " << ((ptrdiff_t) (*h));
+ if (h == topOfHeap) {
+ os << " <---" << endl;
+ break;
+ }
+
+ os << endl;
+ }
+ }
+ os << "-----------------------------" << endl;
+
+
+ UChar* uc = iv_clTemporaryStringHeap.getHeapStart();
+ size_t topOfStringHeap = iv_clTemporaryStringHeap.getTopOfHeap();
+
+ if (false) {
+ os << "PLAIN STRING TABLE" << endl;
+ while ((uc-iv_clTemporaryStringHeap.getHeapStart())<topOfStringHeap) {
+ os << (ptrdiff_t) uc << ": " << *uc << "(" << (ptrdiff_t) (*uc) << ")" << endl;
+ ++uc;
+ }
+ os << "-----------------------------" << endl;
+ uc = iv_clTemporaryStringHeap.getHeapStart();
+ topOfStringHeap = iv_clTemporaryStringHeap.getTopOfHeap();
+ }
+ os << "String table: " << endl;
+ while ( (uc-iv_clTemporaryStringHeap.getHeapStart()) < topOfStringHeap) {
+ UnicodeStringRef uls(uc);
+ os << " " << (ptrdiff_t) uc << ": " << uls << endl;
+ uc += uls.length() + 1;
+ }
+
+ os << "-----------------------------" << endl;
+ os << "HEAP:" << endl;
+ h = iv_clTemporaryHeap.getHeapStart() + 1;
+ int n=1;
+ while (h<lastHeapCell) {
+ if ( (*h) == 0 ) {
+ return;
+ }
+ TyFS currentFS = h;
+ TyFSType type = getType( h );
+ icu::UnicodeString typeName = iv_rclTypeSystem.getTypeName(type);
+ os << n++ << ": (" << (ptrdiff_t) h << ")| " << typeName << endl;
+ ++h;
+ int i;
+ for (i=0; i< (int) iv_rclTypeSystem.getFeatureNumber(type); ++i) {
+ os << n++ << ": (" << (ptrdiff_t) h << ")| " << ((ptrdiff_t) (*h)) << endl;
+ ++h;
+ }
+ if (iv_rclTypeSystem.subsumes( uima::internal::gs_tyArrayBaseType, type) ) {
+ ++h; // for the array size field
+ int iArraySize = getArraySize(currentFS);
+ for (i=0; i<iArraySize; ++i) {
+ os << n++ << ": (" << (ptrdiff_t) h << ")| " << ((ptrdiff_t) (*h)) << endl;
+ ++h;
+ }
+ }
+ }
+#endif
+ }
+#if defined( _MSC_VER )
+#pragma warning( pop )
+#endif
+
+#ifdef ASSERT_OR_RETURN_FALSE
+#error ASSERT_OR_RETURN_FALSE already defined
+#endif
+#define ASSERT_OR_RETURN_FALSE(x) if (!(x)) return false
+//#define ASSERT_OR_RETURN_FALSE(x) assert(x)
+
+
+ bool FSHeap::debugIsConsistent() const {
+#ifdef BYEBYEPTRS
+ if (iv_clTemporaryHeap.getSegmentNumber() >= 1) {
+ return true;
+ }
+// print(cout);
+ static int debugCheck = 0;
+ // cerr << " debugCheck: " << debugCheck << endl;
+ ++debugCheck;
+ if ( (debugCheck % 1) != 0) {
+// return true;
+ }
+ UIMA_TPRINT(" doing check... (debugCheck: " << debugCheck << ")");
+ TyFSType integerType = iv_rclTypeSystem.getTypeByName("uima.cas.Integer");
+ TyFSType floatType = iv_rclTypeSystem.getTypeByName("uima.cas.Float");
+ TyFSType stringType = iv_rclTypeSystem.getTypeByName("uima.cas.String");
+
+ size_t lastHeapCell = iv_clTemporaryHeap.getLastHeapCell();
+ size_t h = 1;
+ while (h<lastHeapCell) {
+ UIMA_TPRINT("Checking heap cell " << ((lastHeapCell-h)) );
+ ASSERT_OR_RETURN_FALSE( EXISTS(h) );
+ ASSERT_OR_RETURN_FALSE( debugIsValidHeapCell(h) );
+
+ if ( (*h) == 0) {
+ do {
+ ASSERT_OR_RETURN_FALSE( (*h) == 0 );
+ ++h;
+ } while (h<lastHeapCell);
+ UIMA_TPRINT(" check done");
+ return true;
+ }
+ ASSERT_OR_RETURN_FALSE( *h != 0 );
+
+ TyFSType type = getType( h );
+ ASSERT_OR_RETURN_FALSE( type != 0 );
+ vector<TyFSFeature> features;
+ iv_rclTypeSystem.getAppropriateFeatures(type, features);
+ ASSERT_OR_RETURN_FALSE( features.size() == iv_rclTypeSystem.getFeatureNumber(type) );
+ size_t i;
+ for (i=0; i<features.size(); ++i) {
+ TyFSFeature f = features[i];
+ TyFSType rangeType = iv_rclTypeSystem.getRangeType( f );
+ if ( (rangeType == integerType)
+ || (rangeType == floatType)
+ || iv_rclTypeSystem.subsumes(stringType, rangeType) ) {}
+ else {
+ if (!isUntouchedFSValue(h,f)) {
+ // type is complex FS
+ TyFS fs = getFSValue(h, f);
+ ASSERT_OR_RETURN_FALSE(debugIsValidHeapCell(fs));
+ TyFSType fsType = getType(fs);
+ ASSERT_OR_RETURN_FALSE( iv_rclTypeSystem.subsumes(rangeType, fsType) );
+ }
+ }
+ }
+ h += features.size() + 1;
+ }
+#endif
+ UIMA_TPRINT(" check done");
+ return true;
+ }
+
+
+ bool FSHeap::debugIsValidHeapCell(TyHeapCell cell) const {
+ return iv_clTemporaryHeap.debugIsValidHeapCell(cell);
+ }
+
+ }
+}
+/* ----------------------------------------------------------------------- */
+
+
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/lowlevel_fsheap.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/lowlevel_index.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/lowlevel_index.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/lowlevel_index.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/lowlevel_index.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,197 @@
+/** \file lowlevel_index.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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_index.hpp"
+#include "uima/lowlevel_fsheap.hpp"
+#include "uima/lowlevel_fsfilter.hpp"
+#include "uima/lowlevel_indexiterator.hpp"
+#include "uima/lowlevel_indexcomparator.hpp"
+#include "uima/lowlevel_indexrepository.hpp"
+#include "uima/msg.h"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+ namespace lowlevel {
+
+ IndexABase::IndexABase(IndexRepository const & crIndexRepository,
+ uima::lowlevel::TyFSType tyType)
+ : iv_crIndexRepository(crIndexRepository),
+ iv_crFSHeap(iv_crIndexRepository.getFSHeap() ),
+ iv_crTypeSystem(iv_crFSHeap.getTypeSystem()),
+ iv_tyFSType(tyType) {
+ assert( iv_crTypeSystem.isValidType(iv_tyFSType) );
+ }
+
+
+ /**
+ * generic implementation of find().
+ */
+ TyFS IndexABase::find(TyFS fs) const {
+ auto_ptr<IndexIterator> it(createIterator());
+ assert( EXISTS(it.get()) );
+ for (it->moveToFirst(); it->isValid(); it->moveToNext() ) {
+ TyFS nextFS = it->get();
+ if (nextFS == fs) {
+ return fs;
+ }
+ }
+ return uima::lowlevel::FSHeap::INVALID_FS;
+ }
+
+
+ /**
+ * An iterator on top of another (decorator) which does simple filtering.
+ */
+ class FilterIndexIterator : public IndexIterator {
+ private:
+ FSFilter const * iv_cpFilter;
+ IndexIterator* iv_pIterator;
+
+ void moveToNextUnfiltered() {
+ while (iv_pIterator->isValid()) {
+ bool bIsFiltered = iv_cpFilter->isFiltered(iv_pIterator->get());
+ if (!bIsFiltered) {
+ return;
+ } else {
+ iv_pIterator->moveToNext();
+ }
+ }
+ }
+
+ void moveToPreviousUnfiltered() {
+ while (iv_pIterator->isValid()) {
+ bool bIsFiltered = iv_cpFilter->isFiltered(iv_pIterator->get());
+ if (!bIsFiltered) {
+ return;
+ } else {
+ iv_pIterator->moveToPrevious();
+ }
+ }
+ }
+
+ public:
+ FilterIndexIterator(FSFilter const * cpFilter, IndexIterator* pIterator)
+ : iv_cpFilter(cpFilter),
+ iv_pIterator(pIterator) {}
+
+ virtual ~FilterIndexIterator() {
+ assert( EXISTS(iv_pIterator) );
+ delete iv_pIterator;
+ }
+
+ void moveToFirst() {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveToFirst();
+ moveToNextUnfiltered();
+ }
+
+ void moveToLast() {
+ assert( EXISTS(iv_pIterator) );
+ iv_pIterator->moveToLast();
+ moveToPreviousUnfiltered();
+ }
+
+ void moveToPrevious() {
+ assert(isValid());
+ iv_pIterator->moveToPrevious();
+ moveToPreviousUnfiltered();
+ }
+
+ void moveToNext() {
+ assert(isValid());
+ iv_pIterator->moveToNext();
+ moveToNextUnfiltered();
+ }
+
+ TyFS get() const {
+ assert(isValid());
+ return iv_pIterator->get();
+ }
+
+ TyFSType getTyFSType() const {
+ assert( isValid() );
+ return iv_pIterator->getTyFSType();
+ }
+
+ bool isValid() const {
+ assert( EXISTS(iv_pIterator) );
+ return iv_pIterator->isValid();
+ }
+
+ IndexIterator* clone() const {
+ return new FilterIndexIterator(iv_cpFilter, iv_pIterator->clone());
+ }
+
+ bool moveTo(TyFS fs) {
+ assert( EXISTS(iv_pIterator) );
+ return iv_pIterator->moveTo(fs);
+ }
+
+ };
+
+
+ IndexIterator* IndexABase::createFilteredIterator(FSFilter const * cpFilter) const {
+ IndexIterator* pit = createIterator();
+ assert( EXISTS(pit) );
+ IndexIterator* result = new FilterIndexIterator(cpFilter, pit);
+ assert( EXISTS(result) );
+ return result;
+ }
+
+ }
+}
+
+
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/lowlevel_index.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/cas/lowlevel_indexcomparator.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/cas/lowlevel_indexcomparator.cpp?view=auto&rev=503248
==============================================================================
--- incubator/uima/uimacpp/trunk/src/cas/lowlevel_indexcomparator.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/cas/lowlevel_indexcomparator.cpp Sat Feb 3 08:54:09 2007
@@ -0,0 +1,312 @@
+/** \file lowlevel_indexcomparator.cpp .
+-----------------------------------------------------------------------------
+
+
+ * 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 */
+/* ----------------------------------------------------------------------- */
+//#define DEBUG_VERBOSE
+
+#include "uima/pragmas.hpp"
+
+#include "uima/macros.h"
+#include "uima/lowlevel_indexcomparator.hpp"
+#include "uima/lowlevel_indexdefinition.hpp"
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+ namespace lowlevel {
+
+ IndexComparator::IndexComparator(IndexDefinition const & indexDefinition,
+ TyFSType tyType,
+ vector<TyFSFeature> const & crIndexs)
+ : iv_indexDefinition( indexDefinition),
+ iv_tyType(tyType) {
+ size_t i;
+ for (i=0; i<crIndexs.size(); ++i) {
+ addKey(crIndexs[i], STANDARD_COMPARE);
+ }
+ }
+
+ IndexComparator::IndexComparator(IndexDefinition const & indexDefinition,
+ TyFSType tyType)
+ : iv_indexDefinition( indexDefinition),
+ iv_tyType(tyType) {
+ }
+
+
+ void IndexComparator::addKey(TyFSFeature tyFeature,
+ EnKeyFeatureComp enComp) {
+ TypeSystem const & crTypeSystem = iv_indexDefinition.getTypeSystem();
+ assert( crTypeSystem.isValidType(iv_tyType) );
+
+ // if this key is type priority
+ if (tyFeature == uima::lowlevel::TypeSystem::INVALID_FEATURE) {
+ iv_features.push_back(uima::lowlevel::TypeSystem::INVALID_FEATURE);
+ iv_offsets.push_back(0);
+ iv_appropTypes.push_back(BUILTIN_TYPE_INVALID);
+ } else {
+ assert( crTypeSystem.isAppropriateFeature(iv_tyType, tyFeature) );
+ iv_features.push_back(tyFeature);
+ iv_offsets.push_back( crTypeSystem.getFeatureOffset(tyFeature) );
+ TyFSType tyAppropType = crTypeSystem.getRangeType(tyFeature);
+
+ if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_INTEGER)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_INTEGER );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_FLOAT)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_FLOAT );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_STRING)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_STRING );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_BOOLEAN)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_BOOLEAN );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_BYTE)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_BYTE );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_SHORT)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_SHORT );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_LONG)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_LONG );
+ } else if (tyAppropType == crTypeSystem.getTypeByName( CAS::TYPE_NAME_DOUBLE)) {
+ iv_appropTypes.push_back( BUILTIN_TYPE_DOUBLE);
+ }
+ else {
+ assertWithMsg(false, "Type not supported for key features!");
+ }
+ }
+ iv_comparators.push_back(enComp);
+
+ assert( iv_offsets.size() == iv_appropTypes.size() );
+ assert( iv_offsets.size() == iv_features.size() );
+ assert( iv_offsets.size() == iv_comparators.size() );
+ }
+
+ inline int
+ inline_strCompare(const UChar *s1, size_t length1,
+ const UChar *s2, size_t length2) {
+ const UChar *limit1;
+ UChar c1, c2;
+
+ /* memcmp/UnicodeString style, both length-specified */
+ int lengthResult;
+
+ /* limit1=s1+min(lenght1, length2) */
+ if (length1<length2) {
+ lengthResult=-1;
+ limit1=s1+length1;
+ } else if (length1==length2) {
+ lengthResult=0;
+ limit1=s1+length1;
+ } else { /* length1>length2 */
+ lengthResult=1;
+ limit1=s1+length2;
+ }
+
+ if (s1==s2) {
+ return lengthResult;
+ }
+
+ for (;;) {
+ /* check pseudo-limit */
+ if (s1==limit1) {
+ return lengthResult;
+ }
+
+ c1=*s1;
+ c2=*s2;
+ if (c1!=c2) {
+ break;
+ }
+ ++s1;
+ ++s2;
+ }
+
+ return(int)c1-(int)c2;
+ }
+
+ int IndexComparator::compare(uima::lowlevel::FSHeap const & heap, TyFS fs1, TyFS fs2) const {
+ if (fs1 == fs2) {
+ return 0;
+ }
+ assert( heap.getTypeSystem().subsumes( iv_tyType, heap.getType(fs1)) );
+ assert( heap.getTypeSystem().subsumes( iv_tyType, heap.getType(fs2)) );
+ UIMA_TPRINT("Comparing fs of type " << heap.getTypeSystem().getTypeName( heap.getType(fs1)));
+ UIMA_TPRINT(" with fs of type " << heap.getTypeSystem().getTypeName( heap.getType(fs2)));
+ bool isGreater = false;
+ bool isLess = false;
+ size_t i;
+ const size_t uiOffsetsSize = iv_offsets.size();
+ TyFeatureOffset utCurrentOffset;
+ // for each feature
+ for (i=0; i <uiOffsetsSize; ++i) {
+ UIMA_TPRINT("Comparing feature " << i);
+ utCurrentOffset = iv_offsets[i];
+ // if type priority
+ if (utCurrentOffset == 0) {
+ assert( iv_features[i] == uima::lowlevel::TypeSystem::INVALID_FEATURE );
+
+ uima::lowlevel::TyFSType t1 = heap.getType(fs1);
+ uima::lowlevel::TyFSType t2 = heap.getType(fs2);
+
+ uima::lowlevel::TypeSystem const & crTypeSystem = heap.getTypeSystem();
+ if (t1 == t2) {
+ isLess = false;
+ isGreater = false;
+ } else if (crTypeSystem.hasPriorityOver(t1, t2)) {
+ isLess = true;
+ isGreater = false;
+ } else {
+ isLess = false;
+ isGreater = true;
+ }
+ } else {
+ TyFS val1 = heap.getFeatureWithOffset(fs1, utCurrentOffset);
+ TyFS val2 = heap.getFeatureWithOffset(fs2, utCurrentOffset);
+ switch (iv_appropTypes[i]) {
+ case BUILTIN_TYPE_INTEGER: {
+ int i1 = FSHeap::getFSAsInt(val1);
+ int i2 = FSHeap::getFSAsInt(val2);
+ UIMA_TPRINT(" val1: " << i1 << ", val2: " << i2);
+ isLess = (i1 < i2);
+ isGreater = (i1 > i2);
+ break;
+ }
+ case BUILTIN_TYPE_FLOAT: {
+ float f1 = FSHeap::getFSAsFloat(val1);
+ float f2 = FSHeap::getFSAsFloat(val2);
+ isLess = (f1 < f2);
+ isGreater = (f1 > f2);
+ break;
+ }
+ case BUILTIN_TYPE_STRING: {
+ UnicodeStringRef us1 = heap.getFSAsString(val1);
+ UnicodeStringRef us2 = heap.getFSAsString(val2);
+ int iCmp = inline_strCompare(us1.getBuffer(), us1.length(),
+ us2.getBuffer(), us2.length());
+ isLess = (iCmp < 0);
+ isGreater = (iCmp > 0);
+ break;
+ }
+ case BUILTIN_TYPE_BOOLEAN: {
+ bool f1 = FSHeap::getFSAsBoolean(val1);
+ bool f2 = FSHeap::getFSAsBoolean(val2);
+ isLess = (f1 < f2);
+ isGreater = (f1 > f2);
+ break;
+ }
+ case BUILTIN_TYPE_BYTE: {
+ char f1 = FSHeap::getFSAsByte(val1);
+ char f2 = FSHeap::getFSAsByte(val2);
+ isLess = (f1 < f2);
+ isGreater = (f1 > f2);
+ break;
+ }
+ case BUILTIN_TYPE_SHORT: {
+ short f1 = FSHeap::getFSAsShort(val1);
+ short f2 = FSHeap::getFSAsShort(val2);
+ isLess = (f1 < f2);
+ isGreater = (f1 > f2);
+ break;
+ }
+ case BUILTIN_TYPE_LONG: {
+ INT64 f1 = heap.getFSAsLong(val1);
+ INT64 f2 = heap.getFSAsLong(val2);
+ isLess = (f1 < f2);
+ isGreater = (f1 > f2);
+ break;
+ }
+ case BUILTIN_TYPE_DOUBLE: {
+ double f1 = heap.getFSAsDouble(val1);
+ double f2 = heap.getFSAsDouble(val2);
+ isLess = (f1 < f2);
+ isGreater = (f1 > f2);
+ break;
+ }
+
+ default:
+// UIMA_TPRINT("Unsupported type: " << heap.getTypeSystem().getTypeName(appropTypes[i]));
+ assertWithMsg(false, "Unsupported built-in type");
+ }
+ }
+ UIMA_TPRINT(" isLess: " << isLess);
+ UIMA_TPRINT(" isGreater: " << isGreater);
+ assert( ! (isLess && isGreater) );
+
+ switch (iv_comparators[i]) {
+ case STANDARD_COMPARE: {
+ if (isLess) {
+ return 1;
+ } else {
+ if (isGreater) {
+ return -1;
+ }
+ }
+ break;
+ }
+ case REVERSE_STANDARD_COMPARE: {
+ if (isLess) {
+ return -1;
+ } else {
+ if (isGreater) {
+ return 1;
+ }
+ }
+ break;
+ }
+ default:
+ assert(false);
+ };
+ }
+ return 0;
+ }
+
+
+ }
+}
+
+
+/* ----------------------------------------------------------------------- */
+
+
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/cas/lowlevel_indexcomparator.cpp
------------------------------------------------------------------------------
svn:eol-style = native