Пример #1
0
Sequence FunctionDocAvailable::createSequence(DynamicContext* context, int flags) const {
  Sequence uriArg = getParamNumber(1,context)->toSequence(context);
  
  if (uriArg.isEmpty()) {
    return Sequence(context->getMemoryManager());
  }
  
  const XMLCh* uri = uriArg.first()->asString(context);
  // on Windows, we can have URIs using \ instead of /; let's normalize them
  XMLCh backSlash[]={ XERCES_CPP_NAMESPACE_QUALIFIER chBackSlash, XERCES_CPP_NAMESPACE_QUALIFIER chNull };
  if(XERCES_CPP_NAMESPACE_QUALIFIER XMLString::findAny(uri,backSlash))
  {
	  XMLCh* newUri=XERCES_CPP_NAMESPACE_QUALIFIER XMLString::replicate(uri,context->getMemoryManager());
	  for(unsigned int i=0;i<XERCES_CPP_NAMESPACE_QUALIFIER XMLString::stringLen(newUri);i++)
		  if(newUri[i]==XERCES_CPP_NAMESPACE_QUALIFIER chBackSlash)
			  newUri[i]=XERCES_CPP_NAMESPACE_QUALIFIER chForwardSlash;
	  uri=newUri;
  }
  if(!XPath2Utils::isValidURI(uri, context->getMemoryManager()))
    XQThrow(FunctionException, X("FunctionDocAvailable::createSequence"), X("Invalid argument to fn:doc-available function [err:FODC0005]"));

  bool bSuccess=false;
  try {
    bSuccess = !context->resolveDocument(uri, this).isEmpty();
  } 
  catch(...) {
  }
  return Sequence(context->getItemFactory()->createBoolean(bSuccess, context), context->getMemoryManager());
}
Пример #2
0
Sequence FunctionAdjustTimeToTimezone::createSequence(DynamicContext* context, int flags) const
{
	XPath2MemoryManager* memMgr = context->getMemoryManager();

  //If $srcval is the empty sequence, then the result is the empty sequence.
  Sequence op1 = getParamNumber(1, context)->toSequence(context);
  if (op1.isEmpty()) {
    return Sequence(memMgr);
  }
  const ATTimeOrDerived* time = (const ATTimeOrDerived*)(const Item*)op1.first();

  //If $timezone is not specified, then $timezone is the value of the implicit timezone in the evaluation context.
  ATDurationOrDerived::Ptr timezoneAsDuration = 0;

  if (getNumArgs() > 1) {
    Sequence op2 = getParamNumber(2, context)->toSequence(context);
    if (op2.isEmpty()) {
      // unset the timezone
      return Sequence(time->setTimezone(0, context), memMgr);
    } else {
      timezoneAsDuration = (const ATDurationOrDerived::Ptr )op2.first();
      Timezone::Ptr timezone = new Timezone(timezoneAsDuration, context);
      if(!timezoneAsDuration->equals(timezone->asDayTimeDuration(context), context)) {
        XQThrow(FunctionException, X("FunctionAdjustTimeToTimeZone::createSequence"),X("Invalid timezone value [err:FODT0003]"));
      }
    }
  }
  else {
    timezoneAsDuration = context->getImplicitTimezone();
  }

  return Sequence(time->addTimezone(timezoneAsDuration, context), memMgr);

}
Пример #3
0
Sequence FunctionLocalname::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager* memMgr = context->getMemoryManager();

  Node::Ptr ctxNode;
  if(getNumArgs() == 1) {
    Sequence arg=getParamNumber(1,context)->toSequence(context);
    if(arg.isEmpty())
      return Sequence(context->getItemFactory()->createString(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString, context), memMgr);
    ctxNode=arg.first();
  }
  else {
    const Item::Ptr item = context->getContextItem();
    if(item==NULLRCP)
      XQThrow(FunctionException, X("FunctionLocalName::createSequence"),X("Undefined context item in fn:local-name [err:XPDY0002]"));
    if(!item->isNode())
      XQThrow(FunctionException, X("FunctionLocalName::createSequence"),X("The context item is not a node [err:XPTY0004]"));
    ctxNode=item;
	}

  ATQNameOrDerived::Ptr name = ctxNode->dmNodeName(context);
  if(name.notNull())
    return Sequence(context->getItemFactory()->createString(((const ATQNameOrDerived*)name.get())->getName(), context), memMgr);

  return Sequence(context->getItemFactory()->createString(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString, context), memMgr);
}
Sequence FunctionMinutesFromDateTime::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager* memMgr = context->getMemoryManager();

  Item::Ptr arg = getParamNumber(1, context)->next(context);
  if(arg.isNull()) return Sequence(memMgr);

  return Sequence(((const ATDateTimeOrDerived*)arg.get())->getMinutes(context), memMgr);
}
Пример #5
0
Sequence FunctionName::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager* mm = context->getMemoryManager();

  Item::Ptr arg = getParamNumber(1,context)->next(context);
  if(arg.isNull())
    return Sequence(context->getItemFactory()->createString(XMLUni::fgZeroLenString, context), mm);

  return Sequence(FunctionString::string_item(((Node*)arg.get())->dmNodeName(context), context), mm);
}
Пример #6
0
 Sequence sequence(const std::string& s)
 {
     std::vector<StateMachineHolder>::iterator existing = std::find(sequences.begin(), sequences.end(), s);
     if( existing == sequences.end() )
     {
         StateMachineHolder h(new StateMachine(s, "0"));
         sequences.push_back(h);
         return Sequence(sequences.back());
     }
     return Sequence(*existing);
 }
Пример #7
0
Sequence FunctionCaseFold::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager *memMgr = context->getMemoryManager();

  Item::Ptr arg = getParamNumber(1, context)->next(context);
  if(arg.isNull()) {
    return Sequence(context->getItemFactory()->createString(XMLUni::fgZeroLenString, context), memMgr);
  }

  AutoDeallocate<XMLCh> buf(UnicodeTransformer::caseFold(arg->asString(context), memMgr), memMgr);
  return Sequence(context->getItemFactory()->createString(buf.get(), context), memMgr);
}
Пример #8
0
Sequence FunctionFloor::createSequence(DynamicContext* context, int flags) const
{
  Numeric::Ptr numericArg = getNumericParam(1, context);

  //If the argument is the empty sequence, the empty sequence is returned.
  if(numericArg.isNull()) {
    return Sequence(context->getMemoryManager());
  }

  if(numericArg->isNaN() || numericArg->isInfinite())
    return Sequence(numericArg, context->getMemoryManager());
  return Sequence(numericArg->floor(context), context->getMemoryManager());
}
Пример #9
0
int
main (int argc, char ** argv) {
	// Creating the instatnce of new machine.
	engine = new StateMachine (matchingHandler);
	IEvent* event = NULL;

	// Creating two sequences to monitor.
	Sequence seqOne = Sequence((int *)SequenceOne, 6, "FIRST");
	Sequence seqTwo = Sequence((int *)SequenceTwo, 4, "ANY");
	// Adding these two sequences to the engine.
	engine->AddSequence(seqOne);
	engine->AddSequence(seqTwo);

	// Handaling the user kill application signal, for clean application close.
	signal(SIGINT, sig_handler);
	// Main loop.
	while (amWorking) {
		switch (TEST[TEST_INDEX]) {
			case STATE_A:
				CreateA (&event);
			break;
			case STATE_B:
				CreateB (&event);
			break;
			case STATE_C:
				CreateC (&event);
			break;
			default:
			break;
		}
		
		if (event != NULL) {
			// Announcing the event.
			engine->SetEvent (event);
		}
		
		// Round test.
		if ((++TEST_INDEX) == 20) {
			TEST_INDEX = 0;
		}
		
		// Fetching event from test repo each one second.
		usleep (1000000 * 1);
	}

	// Resource free.
	delete engine;
	
	std::cout << "Exit 'state-test'" << std::endl;
	return 0;
}
Пример #10
0
Sequence FunctionRound::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager* memMgr = context->getMemoryManager();

  Numeric::Ptr numericArg = getNumericParam(1, context);
    
  //If the argument is the empty sequence, the empty sequence is returned.
  if(numericArg.isNull()) {
    return Sequence(memMgr);
  }

  if(numericArg->isNaN() || numericArg->isInfinite())
    return Sequence(numericArg, memMgr);
  return Sequence(numericArg->round(context), memMgr);
}
Пример #11
0
int main() {
	int* seq = NULL; //seq = 0
	double sum_val = 2.397; //2.397
	seq = Sequence(1,3);
	printf(seq);
	return 0;
}
Пример #12
0
Sequence FunctionSentences::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager* memMgr = context->getMemoryManager();

  // If the value of $operand1 is the empty sequence, the empty sequence is returned.
  Item::Ptr inputString = getParamNumber(1,context)->next(context);
  if(inputString.isNull())
    return Sequence(memMgr);

  const XMLCh *input=inputString->asString(context);
  AutoDeallocate<XMLCh> buf(UnicodeTransformer::sentences(input, memMgr), memMgr);

  XMLCh* rb = buf.get();
  XMLCh* start = NULL;
  Sequence resultSeq(0, memMgr);

  // Build sequence
  for (int i = 0; rb[i]; i++) {
    if (rb[i] != UTF8PROC_SB_MARK)
      continue;

    rb[i] = 0;
    if (rb[i+1] == 0 || rb[i+1] != UTF8PROC_SB_MARK) {
      if (start != NULL)
        resultSeq.addItem(context->getItemFactory()->createString(start, context));
      start = rb + (i+1);
    }
  }

  return resultSeq;
}
Пример #13
0
std::vector<Sequence> AnySuitCondition::GetVariants(const Sequence& applied_sequence,
                                                    Storage storage) const {
    if (applied_sequence.IsOccupied(position_)) {
        if (!inverse_ && applied_sequence.GetCard(position_).rank != rank_) {
            return {};
        }
        if (inverse_ && applied_sequence.GetCard(position_).rank == rank_) {
            return {};
        }
        return {
            Sequence(SimpleSequence{{applied_sequence.GetCard(position_)}, position_})};
    }
    std::vector<Card> cards;
    if (!inverse_) {
        for (auto& suit : storage.GetSuitsForRank(rank_)) {
            cards.push_back(Card{suit, rank_});
        }
    } else {
        for (auto& card : storage.GetAllAvailableCards()) {
            if (card.rank != rank_) {
                cards.push_back(card);
            }
        }
    }
    std::vector<Sequence> result;
    for (auto& card : cards) {
        result.emplace_back(SimpleSequence{{card}, position_});
    }
    return result;
}
Пример #14
0
Sequence FunctionDoc::createSequence(DynamicContext* context, int flags) const
{
  Item::Ptr uriArg = getParamNumber(1,context)->next(context);
  
  if(uriArg.isNull()) {
    return Sequence(context->getMemoryManager());
  }
  
  const XMLCh *uri = uriArg->asString(context);

  // on Windows, we can have URIs using \ instead of /; let's normalize them
  if(uri != 0) {
    unsigned int len = XPath2Utils::uintStrlen(uri);
    AutoDeleteArray<XMLCh> newURI(new XMLCh[len + 1]);

    const XMLCh *src = uri;
    XMLCh *dst = newURI;
    while(*src != 0) {
      if(*src == '\\') *dst = '/';
      else *dst = *src;

      ++src; ++dst;
    }
    *dst = 0;

    uri = context->getMemoryManager()->getPooledString(newURI);
  }

  if(!XPath2Utils::isValidURI(uri, context->getMemoryManager()))
    XQThrow(FunctionException, X("FunctionDoc::createSequence"), X("Invalid argument to fn:doc function [err:FODC0005]"));

  return context->resolveDocument(uri, this, context->getProjection() ? queryPathTree_ : 0);
}
Пример #15
0
void vargas::SAM::Header::parse(std::string hdr) {
    sorting_order = "";
    grouping = "";
    sequences.clear();
    read_groups.clear();
    programs.clear();

    std::vector<std::string> lines = split(hdr, '\n');

    // @HD line
    std::vector<std::string> tags = split(lines[0], '\t');
    if (tags[0] != "@HD") throw std::invalid_argument("First line must start with \"@HD\"");
    std::vector<std::string> pair;
    for (auto &p : tags) {
        if (p.at(0) == '@') continue;
        split(p, ':', pair);
        if (pair.size() != 2) continue;
        if (pair[0] == "VN") {
            version = pair[1];
        } else if (pair[0] == "SO") {
            sorting_order = pair[1];
        } else if (pair[0] == "GO") {
            grouping = pair[1];
        }
    }

    // Other lines
    for (auto &l : lines) {
        std::string tag = l.substr(0, 3);
        if (tag == "@SQ") add(Sequence(l));
        else if (tag == "@RG") add(ReadGroup(l));
        else if (tag == "@PG") add(Program(l));
    }
}
Пример #16
0
Sequence FunctionCompare::createSequence(DynamicContext* context, int flags) const
{
    Sequence str1 = getParamNumber(1,context)->toSequence(context);
    Sequence str2 = getParamNumber(2,context)->toSequence(context);
    if(str1.isEmpty() || str2.isEmpty())
        return Sequence(context->getMemoryManager());

    Collation* collation = NULL;
    if(getNumArgs()>2) {
        Sequence collArg = getParamNumber(3,context)->toSequence(context);
        const XMLCh* collName = collArg.first()->asString(context);
        try {
            context->getItemFactory()->createAnyURI(collName, context);
        } catch(XPath2ErrorException &e) {
            XQThrow(FunctionException, X("FunctionCompare::createSequence"), X("Invalid argument to compare function"));  
        }
        collation = context->getCollation(collName, this);
        if(collation == NULL)
            XQThrow(FunctionException,X("FunctionCompare::createSequence"),X("Collation object is not available"));
    }
    else
        collation = context->getDefaultCollation(this);
    if(collation == NULL)
        collation = context->getCollation(CodepointCollation::getCodepointCollationName(), this);

    const XMLCh* string1 = str1.first()->asString(context);
    const XMLCh* string2 = str2.first()->asString(context);
    Sequence result(context->getItemFactory()->createInteger(collation->compare(string1,string2), context), context->getMemoryManager());

    return result;
}
Пример #17
0
void f2_fft_indexed(int log2n, const complex_t *pIn, complex_t *pOut)
{
    const complex_t wn_table[16]={
      complex_t::from_float(1,     -2.44929359829471e-16),
      complex_t::from_float(-1,     1.22464679914735e-16),
      complex_t::from_float(6.12323399573677e-17, 1),
      complex_t::from_float(0.707106781186548,         0.707106781186547),
      complex_t::from_float(0.923879532511287,          0.38268343236509),
      complex_t::from_float(0.98078528040323 ,        0.195090322016128),
      complex_t::from_float(0.995184726672197 ,       0.0980171403295606),
      complex_t::from_float(0.998795456205172,         0.049067674327418),
      complex_t::from_float(0.999698818696204,        0.0245412285229123),
      complex_t::from_float(0.999924701839145,        0.0122715382857199),
      complex_t::from_float(0.999981175282601,       0.00613588464915448),
      complex_t::from_float(0.999995293809576,       0.00306795676296598),
      complex_t::from_float(0.999998823451702,       0.00153398018628477),
      complex_t::from_float(0.999999705862882,      0.000766990318742704),
      complex_t::from_float(0.999999926465718,      0.000383495187571396),
      complex_t::from_float(0.999999981616429,      0.000191747597310703)
    };

    int n=1<<log2n;
    complex_t wn=wn_table[log2n];
    int bIn=0;
    int sIn=1;
    int bOut=0;
    int sOut=1;

    run_function_old<void>(
        IfElse([&](){ return n<=2; },
            [&](){
                if (n == 1){
                    pOut[bOut+0] = pIn[bIn+0];
                }else if (n == 2){
                    pOut[bOut+0] = pIn[bIn+0]+pIn[bIn+sIn];
                    pOut[bOut+sOut] = pIn[bIn+0]-pIn[bIn+sIn];
                }
            },
            Sequence(
                [&](){
                    n=n/2;
                },
                Recurse([&](){ return make_hls_state_tuple(n,wn*wn,bIn,2*sIn,bOut,sOut); }),
                Recurse([&](){ return make_hls_state_tuple(n,wn*wn,bIn+sIn,2*sIn,bOut+sOut*n,sOut); }),
                [&](){
                    complex_t w=complex_t::from_int(1);

                    for (int j=0;j<n;j++){
                        complex_t t1 = w*pOut[bOut+n+j];
                        complex_t t2 = pOut[bOut+j]-t1;
                        pOut[bOut+j] = pOut[bOut+j]+t1;
                        pOut[bOut+j+n] = t2;
                        w = w*wn; // This introduces quite a lot of numerical error
                    }
                }
            )
        ),
        n, wn, bIn, sIn, bOut, sOut
    );
}
TEST_F(TestPacketFragment, Fragments)
{
    auto toTest1 = PacketFragment{Sequence(0), {0,1,2,3,4,5,6,7}, 7, 0};
    auto toTest2 = PacketFragment{Sequence(0), {0,1,2,3,4,5,6,7}, 7, 1};
    std::vector<uint8_t> payload1(GetPayloadBuffer(toTest1));
    std::vector<uint8_t> payload2(GetPayloadBuffer(toTest2));

    // first
    EXPECT_TRUE(toTest1.IsValid());
    EXPECT_EQ(0, toTest1.FragmentId());
    EXPECT_FALSE(toTest1.IsLastFragment());

    // second
    EXPECT_TRUE(toTest2.IsValid());
    EXPECT_EQ(1, toTest2.FragmentId());
    EXPECT_TRUE(toTest2.IsLastFragment());
}
Пример #19
0
Sequence FunctionTimezoneFromDate::createSequence(DynamicContext* context, int flags) const
{
	XPath2MemoryManager* memMgr = context->getMemoryManager();

  Sequence arg=getParamNumber(1,context)->toSequence(context);
  if(arg.isEmpty())
    return Sequence(memMgr);

  const ATDateOrDerived *date = (const ATDateOrDerived*)(const Item*)arg.first();
  // If $srcval does not contain a timezone, the result is the empty sequence
  if (date->hasTimezone() == false) {
    return Sequence(memMgr);
  }

  const Timezone::Ptr timezone = date->getTimezone();
  return Sequence( (const Item::Ptr )timezone->asDayTimeDuration(context), memMgr );
}
Пример #20
0
Sequence FunctionLast::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager* memMgr = context->getMemoryManager();

  if(context->getContextItem()==NULLRCP)
    XQThrow(DynamicErrorException,X("FunctionPosition::createSequence"), X("Undefined context item in fn:last [err:XPDY0002]"));
  return Sequence(context->getItemFactory()->createInteger((long)context->getContextSize(), context), memMgr);
}
Пример #21
0
matrix ConstructSequence(const vector& dt, const vector& x) {
	int Order = dt.GetLength();
	matrix Sequence(Order,1);
	
	for(int i = Order; i > 0; i--)
			Sequence[i-1] = ComputeRecursiveDerivative(i,i,i,dt,x,Sequence[i-1]);
	
	return Sequence;
} 	
Пример #22
0
Sequence FunctionParseXML::createSequence(DynamicContext* context, int flags) const
{
  Item::Ptr item = getParamNumber(1, context)->next(context);

  if(item.isNull()) return Sequence(context->getMemoryManager());

  const XMLCh *xml = item->asString(context);

  MemBufInputSource src((XMLByte*)xml, XMLString::stringLen(xml) * sizeof(XMLCh), name);
  src.setEncoding(XMLUni::fgUTF16EncodingString);

  try {
    return Sequence(context->parseDocument(src, this, context->getProjection() ? queryPathTree_ : 0), context->getMemoryManager());
  }
  catch(XMLParseException &e) {
    XQThrow(FunctionException, X("FunctionParseXML::createSequence"), e.getError());
  }
}
Пример #23
0
void ShutdownHook(void)
{
	Sequence(2);
	/* \treq EH_07 nmf B1B2E1E2 se CheckShutdownHook: ShutdownOS
	 *
	 * \result ShutdowHook is called after os shutdown
	 * 
	 */
	ASSERT(EH_07,0);

	Sequence(3);

	/* evaluate conformance tests */
	ConfTestEvaluation();

	/* finish the conformance test */
	ConfTestFinish();
}
Пример #24
0
Sequence FunctionStringLength::createSequence(DynamicContext* context, int flags) const
{
  XPath2MemoryManager *mm = context->getMemoryManager();

  Item::Ptr strParm = getParamNumber(1,context)->next(context);
  if(strParm.isNull())
    return Sequence(context->getItemFactory()->createInteger(0, context), mm);

  const XMLCh *str = strParm->asString(context);

  long length = 0;
  while(*str) {
    ++length;
    if(RegxUtil::isHighSurrogate(*str)) ++str;
    ++str;
  }

  return Sequence(context->getItemFactory()->createInteger(length, context), mm);
}
 void OutputSequences(string output_fname) const {
     ofstream out(output_fname.c_str());
     size_t id = 1;
     for(auto it = begin(); it != end(); it++) {
         out << ">antibody_" << id << endl;
         out << it->Sequence() << endl;
         id++;
     }
     out.close();
 }
Пример #26
0
Model::Human::Human(IPlayer* Player, Manager::Resource* Resource[MajorCount], DWORD Subtype)
    : Model::Unit(Player, Resource[MajorSolider], Model::ModelHuman, Subtype)
{
    ZeroMemory(m_MajorSkills, sizeof(m_MajorSkills));
    memcpy(m_Skins, Resource, sizeof(m_Skins));

    SetMajor(MajorSolider);

    m_Seq = Sequence(1.0f, Animations[AnimNone]);
}
Пример #27
0
Sequence FlowData::getSequence(){
	
	try{
		return Sequence(seqName, sequence);
	}
	catch(exception& e) {
		m->errorOut(e, "FlowData", "getSequence");
		exit(1);
	}
}
Пример #28
0
Sequence FunctionConcat::createSequence(DynamicContext* context, int flags) const
{
  XMLBuffer result;
  for(unsigned int i = 1; i <= getNumArgs(); ++i) {
    Item::Ptr item = getParamNumber(i,context)->next(context);
    if(!item.isNull()) {
      result.append(item->asString(context));
    }
  }
  return Sequence(context->getItemFactory()->createString(result.getRawBuffer(), context), context->getMemoryManager());
}
Пример #29
0
Sequence FunctionCount::createSequence(DynamicContext* context, int flags) const
{
  Result arg = getParamNumber(1,context);

  long length = 0;
  while(arg->next(context).notNull()) {
    ++length;
  }

  return Sequence(context->getItemFactory()->createInteger(length, context), context->getMemoryManager());
}
Пример #30
0
Model::Human::Human(Model::Human* Unit)
    : Model::Unit(Unit)
{
    memcpy(m_MajorSkills, Unit->m_MajorSkills, sizeof(m_MajorSkills));
    memcpy(m_Skins, Unit->m_Skins, sizeof(m_Skins));

    SetMajor((Major)ds::Math::RandomInt(0, MajorCount));

    m_Seq = Sequence(0.1f, Animations[AnimNone]);
    m_Random = ds::Timer(ds::Math::RandomFloat(0.6f, 10.0f));
}