예제 #1
0
VectorOf<Word>
PresentationParser::parseWordList( const VectorOf<Chars>& names, Chars& errMesg )
{
  genNames = names;

  if ( curToken == INIT ) getToken();

  ListOf<Word> result;

  if ( curToken == INIT ) getToken();

  while ( atStartOfWord() ) {
    Word w = parseWord( names, errMesg );
    if ( errMesg.length() > 0 ) {
      return makeVectorOf(result);
    }
    result.append( w );

    if ( curToken == COMMA ) {
      getToken();
      if ( !atStartOfWord() ) {
	parseError("Expected a word here");
	errMesg = parseErrorMessage;
	return makeVectorOf(result);
      }
    }
  }

  return makeVectorOf(result);
}
예제 #2
0
// [[Rcpp::export]]
ListOf<CharacterVector> qatd_cpp_unhash(ListOf<IntegerVector> tokens_int, 
                                        CharacterVector types){
    
    types.push_front(""); // offset types to match index in R
    List tokens_chr(tokens_int.size());
    for(int i=0; i < tokens_int.size(); i++){
        tokens_chr[i] = types[tokens_int[i]];
    }
    return tokens_chr;
}
END_TEST


START_TEST ( test_InitialAssignment_parent_create )
{
    Model *m = new Model(2, 4);
    InitialAssignment *ia = m->createInitialAssignment();

    ListOf *lo = m->getListOfInitialAssignments();

    fail_unless(lo == m->getInitialAssignment(0)->getParentSBMLObject());
    fail_unless(lo == ia->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_FunctionDefinition_parent_create )
{
    Model *m = new Model(2, 4);
    FunctionDefinition *fd = m->createFunctionDefinition();

    ListOf *lo = m->getListOfFunctionDefinitions();

    fail_unless(lo == m->getFunctionDefinition(0)->getParentSBMLObject());
    fail_unless(lo == fd->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Reaction_parent_create )
{
    Model *m = new Model(2, 4);
    Reaction *r = m->createReaction();

    ListOf *lo = m->getListOfReactions();

    fail_unless(lo == m->getReaction(0)->getParentSBMLObject());
    fail_unless(lo == r->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_SpeciesReference_Reactant_parent_create )
{
    Reaction *r = new Reaction(2, 4);
    SpeciesReference *sr = r->createReactant();

    ListOf *lo = r->getListOfReactants();

    fail_unless(lo == r->getReactant(0)->getParentSBMLObject());
    fail_unless(lo == sr->getParentSBMLObject());
    fail_unless(r == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Event_parent_create )
{
    Model *m = new Model(2, 4);
    Event *e = m->createEvent();

    ListOf *lo = m->getListOfEvents();

    fail_unless(lo == m->getEvent(0)->getParentSBMLObject());
    fail_unless(lo == e->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_CompartmentType_parent_create )
{
    Model *m = new Model(2, 4);
    CompartmentType *ct = m->createCompartmentType();

    ListOf *lo = m->getListOfCompartmentTypes();

    fail_unless(lo == m->getCompartmentType(0)->getParentSBMLObject());
    fail_unless(lo == ct->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Constraint_parent_create )
{
    Model *m = new Model(2, 4);
    Constraint *ct = m->createConstraint();

    ListOf *lo = m->getListOfConstraints();

    fail_unless(lo == m->getConstraint(0)->getParentSBMLObject());
    fail_unless(lo == ct->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_SpeciesType_parent_create )
{
    Model *m = new Model(2, 4);
    SpeciesType *st = m->createSpeciesType();

    ListOf *lo = m->getListOfSpeciesTypes();

    fail_unless(lo == m->getSpeciesType(0)->getParentSBMLObject());
    fail_unless(lo == st->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_SpeciesReference_Modifier_parent_create )
{
    Reaction *r = new Reaction(2, 4);
    ModifierSpeciesReference *sr = r->createModifier();

    ListOf *lo = r->getListOfModifiers();

    fail_unless(lo == sr->getParentSBMLObject());
    fail_unless(lo == r->getModifier(0)->getParentSBMLObject());
    fail_unless(r == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_UnitDefinition_parent_create )
{
    Model *m = new Model(2, 4);
    UnitDefinition *ud = m->createUnitDefinition();

    ListOf *lo = m->getListOfUnitDefinitions();

    fail_unless(lo == m->getUnitDefinition(0)->getParentSBMLObject());
    fail_unless(lo == ud->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_RateRule_parent_create )
{
    Model *m = new Model(2, 4);
    RateRule *r = m->createRateRule();

    ListOf *lo = m->getListOfRules();

    fail_unless(lo == m->getRule(0)->getParentSBMLObject());
    fail_unless(lo == r->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Parameter_parent_create )
{
    Model *m = new Model(2, 4);
    Parameter *p = m->createParameter();

    ListOf *lo = m->getListOfParameters();

    fail_unless(lo == m->getParameter(0)->getParentSBMLObject());
    fail_unless(lo == p->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_SpeciesReference_Product_parent_create_model )
{
    Model *m = new Model(2, 4);
    Reaction *r = m->createReaction();
    SpeciesReference *sr = m->createProduct();

    ListOf *lo = r->getListOfProducts();

    fail_unless(lo == r->getProduct(0)->getParentSBMLObject());
    fail_unless(lo == sr->getParentSBMLObject());
    fail_unless(r == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_EventAssignment_parent_create )
{
    Event *e = new Event(2, 4);

    EventAssignment *ea = e->createEventAssignment();

    ListOf *lo = e->getListOfEventAssignments();

    fail_unless(lo == e->getEventAssignment(0)->getParentSBMLObject());
    fail_unless(lo == ea->getParentSBMLObject());
    fail_unless(e == lo->getParentSBMLObject());
}
예제 #17
0
/*
 * The functions determins wether the given UnitDefinition contains only
 * units from the list given as the second argument.
 * @param const UnitDefinition& uDef
 * @param const ListOf& unitList
 * @return bool containsOnlyGivenUnits
 */
LIBSBML_EXTERN
bool UnitConversionFactory::containsOnlyGivenUnits(const UnitDefinition& uDef, const ListOf& unitList)
{
    bool result = true;
    UnitDefinition* pTmpUdef = UnitConversionFactory::convertToSI(uDef);

    if (pTmpUdef)
    {
        unsigned int i;
        unsigned int maxUnits = pTmpUdef->getNumUnits();

        for (i = 0; i < maxUnits; ++i)
        {
            Unit* pU = pTmpUdef->getUnit(i);
            UnitKind_t kind = pU->getKind();
            unsigned int j;
            unsigned int maxUnits2 = unitList.size();
            bool found = false;

            for (j = 0; j < maxUnits2; ++j)
            {
                const Unit* pU2 = dynamic_cast<const Unit*>(unitList.get(j));

                if (!pU2) break;

                if (pU2->getKind() == kind)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                result = false;
                break;
            }
        }

        delete pTmpUdef;
    }
    else
    {
        result = false;
    }

    return result;
}
예제 #18
0
파일: ungroup.cpp 프로젝트: lexqbit/gggeom
// Convert a list of numeric vectors into a single numeric vector where
// each original vector is followed by an NA
// [[Rcpp::export]]
NumericVector ungroupNA(ListOf<NumericVector> x) {
  int n = x.size();

  // Figure out total size needed
  int n_total = 0;
  for (int i = 0; i < n; ++i) {
    n_total += x[i].size();
  }
  n_total += n;

  NumericVector out(n_total);
  int k = 0;
  for (int i = 0; i < n; ++i) {
    NumericVector xi = x[i];
    int ni = xi.size();

    for (int j = 0; j < ni; ++j, ++k) {
      out[k] = xi[j];
    }

    out[k++] = NA_REAL;
  }

  return out;
}
END_TEST


START_TEST ( test_Constraint_parent_add )
{
    Constraint *ct = new Constraint(2, 4);
    Model *m = new Model(2, 4);
    ct->setMath(SBML_parseFormula("a-k"));
    m->addConstraint(ct);

    delete ct;

    ListOf *lo = m->getListOfConstraints();

    fail_unless(lo == m->getConstraint(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_CompartmentType_parent_add )
{
    CompartmentType *ct = new CompartmentType(2, 4);
    Model *m = new Model(2, 4);
    ct->setId("ct");
    m->addCompartmentType(ct);

    delete ct;

    ListOf *lo = m->getListOfCompartmentTypes();

    fail_unless(lo == m->getCompartmentType(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Reaction_parent_add )
{
    Reaction *ia = new Reaction(2, 4);
    Model *m = new Model(2, 4);
    ia->setId("k");

    m->addReaction(ia);

    delete ia;

    ListOf *lo = m->getListOfReactions();

    fail_unless(lo == m->getReaction(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_SpeciesReference_Reactant_parent_add )
{
    SpeciesReference *sr = new SpeciesReference(2, 4);
    Reaction *r = new Reaction(2, 4);

    sr->setSpecies("s");
    r->addReactant(sr);

    delete sr;

    ListOf *lo = r->getListOfReactants();

    fail_unless(lo == r->getReactant(0)->getParentSBMLObject());
    fail_unless(r == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_SpeciesReference_Modifier_parent_add )
{
    ModifierSpeciesReference *sr = new ModifierSpeciesReference(2, 4);
    sr->setSpecies("s");
    Reaction *r = new Reaction(2, 4);

    r->addModifier(sr);

    delete sr;

    ListOf *lo = r->getListOfModifiers();

    fail_unless(lo == r->getModifier(0)->getParentSBMLObject());
    fail_unless(r == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Unit_parent_create )
{
    UnitDefinition* ud = new UnitDefinition(2, 4);
    Unit * u = ud->createUnit();

    fail_unless(ud->getNumUnits() == 1);

    ListOf *lo = ud->getListOfUnits();

    fail_unless(lo == ud->getUnit(0)->getParentSBMLObject());
    fail_unless(lo == u->getParentSBMLObject());
    fail_unless(ud == lo->getParentSBMLObject());

    delete ud;
}
END_TEST


START_TEST ( test_SpeciesType_parent_add )
{
    SpeciesType *ia = new SpeciesType(2, 4);
    ia->setId("s");
    Model *m = new Model(2, 4);

    m->addSpeciesType(ia);

    delete ia;

    ListOf *lo = m->getListOfSpeciesTypes();

    fail_unless(lo == m->getSpeciesType(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_Parameter_parent_add )
{
    Parameter *ia = new Parameter(2, 4);
    Model *m = new Model(2, 4);
    ia->setId("p");

    m->addParameter(ia);

    delete ia;

    ListOf *lo = m->getListOfParameters();

    fail_unless(lo == m->getParameter(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_InitialAssignment_parent_add )
{
    InitialAssignment *ia = new InitialAssignment(2, 4);
    Model *m = new Model(2, 4);
    ia->setSymbol("c");
    ia->setMath(SBML_parseFormula("9"));

    m->addInitialAssignment(ia);

    delete ia;

    ListOf *lo = m->getListOfInitialAssignments();

    fail_unless(lo == m->getInitialAssignment(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_FunctionDefinition_parent_add )
{
    FunctionDefinition *fd = new FunctionDefinition(2, 4);
    Model *m = new Model(2, 4);
    fd->setId("fd");
    fd->setMath(SBML_parseFormula("l"));

    m->addFunctionDefinition(fd);

    delete fd;

    ListOf *lo = m->getListOfFunctionDefinitions();

    fail_unless(lo == m->getFunctionDefinition(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_UnitDefinition_parent_add )
{
    UnitDefinition *ia = new UnitDefinition(2, 4);
    Model *m = new Model(2, 4);
    ia->setId("u");
    ia->createUnit();

    m->addUnitDefinition(ia);

    delete ia;

    ListOf *lo = m->getListOfUnitDefinitions();

    fail_unless(lo == m->getUnitDefinition(0)->getParentSBMLObject());
    fail_unless(m == lo->getParentSBMLObject());
}
END_TEST


START_TEST ( test_EventAssignment_parent_add )
{
    Event *e = new Event(2, 4);
    EventAssignment *ea = new EventAssignment(2, 4);
    ea->setVariable("c");
    ea->setMath(SBML_parseFormula("K+L"));

    e->addEventAssignment(ea);

    delete ea;

    ListOf *lo = e->getListOfEventAssignments();

    fail_unless(lo == e->getEventAssignment(0)->getParentSBMLObject());
    fail_unless(e == lo->getParentSBMLObject());
}