void EngineBase::destroyIfNeeded() {
            util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);

            try {
                if (iv_state == EngineState::enEngineState_readyForProcessOrReconfigOrDeinit) {
                    destroy();
                    iv_state.assertMatch(EngineState::enEngineState_readyForDeletion);
                }
            } catch (ExcWinCException& rclException) {
                // windows "exceptions" are really abort signals: we re-throw for app to handle
                throw rclException;
            } catch (Exception& rclException) {
                clTrace.dump("Unexpected UIMACPP exception");
                clTrace.dump(rclException.asString().c_str());
                assertWithMsg(false, _TEXT(
                "Unexpected UIMACPP exception in engine destructor"));   //lint !e506: Constant value Boolean
            } catch (std::exception& rclException) {
                clTrace.dump("ANSI C++ exception");
                clTrace.dump(rclException.what());
                assertWithMsg(false, _TEXT(
                "Unexpected ANSI C++ exception in engine destructor"));   //lint !e506: Constant value Boolean
            }
#ifdef NDEBUG
      catch (...) {
        /* this should never occur!!! */
        clTrace.dump(_TEXT("Unexpected exception"));
        assertWithMsg(false, _TEXT("Unexpected unknown exception in engine destructor"));   //lint !e506: Constant value Boolean
      }
#endif
        }
Beispiel #2
0
  void BasicArrayFS<T, ARRAY_TYPE>::copyToArray(
    size_t uiStart,
    size_t uiEnd,
    T* destArray,
    size_t uiDestOffset) const {
      checkValidity(UIMA_MSG_ID_EXCON_GETTING_FS_FROM_ARRAY);
      checkArraySize(iv_tyFS, iv_cas->getHeap(), uiEnd - uiStart - 1 , UIMA_MSG_ID_EXCON_GETTING_FS_FROM_ARRAY);
      uima::lowlevel::TyFSType typecode = iv_cas->getHeap()->getType(iv_tyFS);

	  size_t srcOffset = uiStart;
	  size_t numelements = uiEnd-uiStart;
	  size_t destOffset = uiDestOffset;

	  if (typecode== uima::internal::gs_tyIntArrayType || 
		  typecode== uima::internal::gs_tyFloatArrayType   ) {
			  iv_cas->getHeap()->copyToArray( srcOffset,iv_tyFS,(uima::lowlevel::TyHeapCell*) destArray,destOffset,numelements);
	  } else if(typecode== uima::internal::gs_tyByteArrayType || 
		        typecode== uima::internal::gs_tyBooleanArrayType) {
		  iv_cas->getHeap()->copyToArray( srcOffset,iv_tyFS,(char*) destArray,destOffset,numelements);
	  } else if(typecode== uima::internal::gs_tyShortArrayType ) {
		  iv_cas->getHeap()->copyToArray( srcOffset,iv_tyFS,(short*) destArray,destOffset,numelements);
      } else if(typecode== uima::internal::gs_tyLongArrayType || 
		        typecode== uima::internal::gs_tyDoubleArrayType) {
		  iv_cas->getHeap()->copyToArray( srcOffset,iv_tyFS,(INT64*) destArray,destOffset,numelements);
      } else {
      assertWithMsg(false, "Not yet implemented");
      UIMA_EXC_THROW_NEW(NotYetImplementedException,
                 UIMA_ERR_NOT_YET_IMPLEMENTED,
                 UIMA_MSG_ID_EXC_NOT_YET_IMPLEMENTED,
                 ErrorMessage(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT),
                 ErrorInfo::unrecoverable
                );
      }
  }
bool randomFilterTest(){
	const int SAMPLE_N = 128*1024;
	SecureRandomDevice<unsigned int> randomBlock(SAMPLE_N);
	std::vector<std::pair<std::string,std::function<bool(unsigned int&)>>> regexCases =
	{
		{ R"([a-z])", [](unsigned int& i){ return 'a'<=i&&i<='z';}},
		{ R"([A-Z])", [](unsigned int& i){ return 'A'<=i&&i<='Z';}},
		{ R"([\d!])", [](unsigned int& i){ return ('0'<=i&&i<='9')||(i=='!');}},
		{ R"([01])", [](unsigned int& i){ return i=='0'||i=='1';}},
		//{ "[]", [](unsigned int& i){ return 'A'<=i&&i<='Z';}},
	};
	for(auto& i:regexCases){
		//print message
		std::cout<<i.first<<"\t";
		//generate random block
		unsigned int* dummy = randomBlock.gen();
		//convert it into std::vector and filter it.
		std::vector<unsigned int> randomChars(dummy, dummy+SAMPLE_N);
		RandomFilter(i.first).filter<unsigned int>(randomChars);
		//If there is an character that is not included in the expression, return false.
		if(std::find_if_not(randomChars.begin(), randomChars.end(), i.second) != randomChars.end())
			return false;
	}
	return true;
}

#include "intTest.h"

int main(){
	assertWithMsg(randomTest);
	assertWithMsg(randomFilterTest);
	assertWithMsg(integrationTests);

	//assertWithMsg([](){ return false; }); //This works.

	std::cout<<"All tests were completed successfully. Hooray! :D"<<std::endl;
	return 0;
}
Beispiel #4
0
 inline AnnotatorContext & Annotator::getAnnotatorContext(void) {
   assertWithMsg(EXISTS(iv_pclAnnotatorContext), "Annotator::init() Forgot to call 'setAnnotatorContext()'");
   return(*iv_pclAnnotatorContext);
 }
Beispiel #5
0
 /*static*/ BasicArrayFS<T, ARRAY_TYPE> BasicArrayFS<T, ARRAY_TYPE>::createArrayFS( CAS & cas, size_t uiSize, bool bIsPermanent) {
   assertWithMsg( sizeof(FeatureStructure::TyArrayElement) == sizeof(lowlevel::TyHeapCell), "Port required");
   uima::lowlevel::FSHeap & heap =  *uima::internal::FSPromoter::getFSHeap(cas);
   lowlevel::TyFS tyFS = heap.createArrayFS(ARRAY_TYPE, uiSize);
   return BasicArrayFS(internal::FSPromoter::promoteFS( tyFS, cas ));
 }