예제 #1
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;
}
예제 #2
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;
}
예제 #3
0
std::vector<CollectorPtr> collectorsCreate(ListOf<List> specs,
                                           LocaleInfo* pLocale,
                                           Warnings* pWarning) {
  std::vector<CollectorPtr> collectors;
  for (int j = 0; j < specs.size(); ++j) {
    CollectorPtr col = Collector::create(specs[j], pLocale);
    col->setWarnings(pWarning);
    collectors.push_back(col);
  }

  return collectors;
}
예제 #4
0
// [[Rcpp::export]]
IntegerVector grouped_indices_impl(DataFrame data, ListOf<Symbol> symbols) {
  int nsymbols = symbols.size();
  if (nsymbols == 0)
    return rep(1, data.nrows());
  CharacterVector vars(nsymbols);
  for (int i=0; i<nsymbols; i++) {
    vars[i] = PRINTNAME(symbols[i]);

    const char* name = vars[i];
    SEXP v;
    try {
      v = data[name];
    } catch (...) {
      stop("unknown column '%s'", name);
    }
    if (!white_list(v) || TYPEOF(v) == VECSXP) {
      stop("cannot group column %s, of class '%s'", name, get_single_class(v));
    }
  }

  DataFrameVisitors visitors(data, vars);
  ChunkIndexMap map(visitors);
  int n = data.nrows();
  train_push_back(map, n);

  DataFrame labels = DataFrameSubsetVisitors(data, vars).subset(map, "data.frame");
  IntegerVector labels_order = OrderVisitors(labels).apply();

  labels = DataFrameSubsetVisitors(labels).subset(labels_order, "data.frame");

  int ngroups = map.size();

  IntegerVector res = no_init(n);

  std::vector<const std::vector<int>* > chunks(ngroups);
  ChunkIndexMap::const_iterator it = map.begin();
  for (int i=0; i<ngroups; i++, ++it) {
    chunks[i] = &it->second;
  }

  for (int i=0; i<ngroups; i++) {
    int idx = labels_order[i];
    const std::vector<int>& v = *chunks[idx];

    int n_index = v.size();
    for (int j=0; j<n_index; j++) {
      res[ v[j] ] = i+1;
    }
  }

  return res;
}
예제 #5
0
// [[Rcpp::export]]
LogicalVector nodes_duplicated(ListOf<XPtrNode> nodes) {
  std::set<xmlNode*> seen;

  int n = nodes.size();
  LogicalVector out(n);

  for (int i = 0; i < n; ++i) {
    XPtrNode node = nodes[i];
    out[i] = !seen.insert(node.get()).second;
  }

  return out;
}
예제 #6
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;
}
예제 #7
0
파일: dplyr.cpp 프로젝트: kevinushey/dplyr
//' @export
//' @rdname rbind
// [[Rcpp::export]]
List rbind_all( ListOf<DataFrame> dots ){
    int ndata = dots.size() ;
    int n = 0 ;
    for( int i=0; i<ndata; i++) n += dots[i].nrows() ;

    std::vector<Collecter*> columns ;
    std::vector<String> names ;
    int k=0 ;
    for( int i=0; i<ndata; i++){
        DataFrame df = dots[i] ;
        DataFrameVisitors visitors( df, df.names() ) ;
        int nrows = df.nrows() ;

        CharacterVector df_names = df.names() ;
        for( int j=0; j<df.size(); j++){
            SEXP source = df[j] ;
            String name = df_names[j] ;

            Collecter* coll = 0;
            size_t index = 0 ;
            for( ; index < names.size(); index++){
                if( name == names[index] ){
                    coll = columns[index] ;
                    break ;
                }
            }
            if( ! coll ){
                coll = collecter( source, n ) ;
                columns.push_back( coll );
                names.push_back(name) ;
            }

            if( coll->compatible(source) ){
                // if the current source is compatible, collect
                coll->collect( SlicingIndex( k, nrows), source ) ;

            } else if( coll->can_promote(source) ) {
                // setup a new Collecter
                Collecter* new_collecter = promote_collecter(source, n, coll ) ;

                // import data from this chunk
                new_collecter->collect( SlicingIndex( k, nrows), source ) ;

                // import data from previous collecter
                new_collecter->collect( SlicingIndex(0, k), coll->get() ) ;

                // dispose the previous collecter and keep the new one.
                delete coll ;
                columns[index] = new_collecter ;

            } else {
                std::stringstream msg ;
                std::string column_name(name) ;
                msg << "incompatible type ("
                    << "data index: "
                    << (i+1)
                    << ", column: '"
                    << column_name
                    << "', was collecting: "
                    << coll->describe()
                    << " ("
                    << DEMANGLE(*coll)
                    << ")"
                    << ", incompatible with data of type: "
                    << type_name(source) ;

                stop( msg.str() ) ;
            }

        }

        k += nrows ;
    }

    int nc = columns.size() ;
    List out(nc) ;
    CharacterVector out_names(nc) ;
    for( int i=0; i<nc; i++){
        out[i] = columns[i]->get() ;
        out_names[i] = names[i] ;
    }
    out.attr( "names" ) = out_names ;
    delete_all( columns ) ;
    set_rownames( out, n );
    out.attr( "class" ) = "data.frame" ;

    return out ;
}
예제 #8
0
//static
void SBMLDocumentLoader::readListOfLayouts(CListOfLayouts & lol,
    const ListOf & sbmlList,
    const std::map<CCopasiObject*, SBase*> & copasimodelmap)
{
  unsigned C_INT32 i, iMax;
#ifdef USE_CRENDER_EXTENSION
  // read the global render information
  const ListOfLayouts* pLoL = dynamic_cast<const ListOfLayouts*>(&sbmlList);
  assert(pLoL != NULL);
  RenderListOfLayoutsPlugin* rlolPlugin = (RenderListOfLayoutsPlugin*) pLoL ->getPlugin("render");

  if (rlolPlugin == NULL)
    {
      const_cast<SBMLDocument *>(pLoL->getSBMLDocument())->enablePackage(RenderExtension::getXmlnsL3V1V1(), "render", true);
      rlolPlugin = (RenderListOfLayoutsPlugin*) pLoL ->getPlugin("render");
    }

  iMax = rlolPlugin->getNumGlobalRenderInformationObjects();
  std::map<std::string, std::string> idToKeyMap;
  CLGlobalRenderInformation* pGRI = NULL;

  /*
  std::map<std::string,std::string> colorIdToKeyMap;
  std::map<std::string,std::string> gradientIdToKeyMap;
  std::map<std::string,std::string> lineEndingIdToKeyMap;
  std::map<std::string,std::map<std::string,std::string> > colorIdToKeyMapMap;
  std::map<std::string,std::map<std::string,std::string> > gradientIdToKeyMapMap;
  std::map<std::string,std::map<std::string,std::string> > lineEndingIdToKeyMapMap;
  */
  for (i = 0; i < iMax; ++i)
    {
      //colorIdToKeyMap.clear();
      //gradientIdToKeyMap.clear();
      //lineEndingIdToKeyMap.clear();
      //pGRI=new CLGlobalRenderInformation(*pLoL->getRenderInformation(i),colorIdToKeyMap,gradientIdToKeyMap,lineEndingIdToKeyMap,&lol);
      pGRI = new CLGlobalRenderInformation(*rlolPlugin->getRenderInformation(i), &lol);

      if (rlolPlugin->getRenderInformation(i)->isSetId())
        idToKeyMap.insert(std::pair<std::string, std::string>(rlolPlugin->getRenderInformation(i)->getId(), pGRI->getKey()));
      else
        idToKeyMap.insert(std::pair<std::string, std::string>(pGRI->getKey(), pGRI->getKey()));

      //colorIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pGRI->getKey(),colorIdToKeyMap));
      //gradientIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pGRI->getKey(),gradientIdToKeyMap));
      //lineEndingIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pGRI->getKey(),lineEndingIdToKeyMap));
      lol.addGlobalRenderInformation(pGRI);
    }

  // fix the references
  SBMLDocumentLoader::convertRenderInformationReferencesIds<CLGlobalRenderInformation>(lol.getListOfGlobalRenderInformationObjects(), idToKeyMap);
  // fix the color ids, gradient ids and line ending ids.
  /*
  std::map<std::string,std::map<std::string,std::string> >::const_iterator mapPos;
  std::map<std::string,std::map<std::string,std::string> > expandedColorIdToKeyMapMap, expandedGradientIdToKeyMapMap, expandedLineEndingIdToKeyMapMap;
  std::map<std::string,std::map<std::string,std::string> > tmpMap1,tmpMap2,tmpMap3;
  for(i=0;i < iMax; ++i)
  {
      pGRI=dynamic_cast<CLGlobalRenderInformation*>(lol.getRenderInformation(i));
      assert(pGRI != NULL);

      std::set<std::string> chain;
      SBMLDocumentLoader::expandIdToKeyMaps<CLGlobalRenderInformation>(pGRI,
                         lol.getListOfGlobalRenderInformationObjects(),
                         expandedColorIdToKeyMapMap,
                         expandedGradientIdToKeyMapMap,
                         expandedLineEndingIdToKeyMapMap,
                         colorIdToKeyMapMap,
                         gradientIdToKeyMapMap,
                         lineEndingIdToKeyMapMap,
                         chain,
                         tmpMap1,
                         tmpMap2,
                         tmpMap3
                  );
      SBMLDocumentLoader::convertPropertyKeys<CLGlobalRenderInformation>(pGRI,expandedColorIdToKeyMapMap[pGRI->getKey()],expandedGradientIdToKeyMapMap[pGRI->getKey()],expandedLineEndingIdToKeyMapMap[pGRI->getKey()]);
  }
      */
#endif /* USE_CRENDER_EXTENSION */
  //convert the map as used by the CLxxx constructors
  std::map<std::string, std::string> modelmap;

  std::string s1, s2;
  std::map<CCopasiObject*, SBase*>::const_iterator it;
  std::map<CCopasiObject*, SBase*>::const_iterator itEnd = copasimodelmap.end();

  for (it = copasimodelmap.begin(); it != itEnd; ++it)
    {
      s1 = SBMLUtils::getIdFromSBase(it->second);

      if (it->first)
        s2 = it->first->getKey();
      else
        s2 = "";

      if ((s1 != "") && (s2 != ""))
        modelmap[s1] = s2;
    }

  //iterate through list of layouts
  iMax = sbmlList.size();

  for (i = 0; i < iMax; ++i)
    {
      std::map<std::string, std::string> layoutmap;
      const Layout* tmp
        = dynamic_cast<const Layout*>(sbmlList.get(i));

      if (tmp)
        {
#ifdef USE_CRENDER_EXTENSION
          //CLayout * pLayout = createLayout(*tmp, modelmap, layoutmap,idToKeyMap,expandedColorIdToKeyMapMap,expandedGradientIdToKeyMapMap,expandedLineEndingIdToKeyMapMap);
          CLayout * pLayout = createLayout(*tmp, modelmap, layoutmap, idToKeyMap);
#else
          CLayout * pLayout = createLayout(*tmp, modelmap, layoutmap);
#endif /* USE_CRENDER_EXTENSION */
          lol.addLayout(pLayout, layoutmap);
        }
    }

  //TODO: the layout object should be added to the copasimodelmap. However,
  //if this is done, the object also need to be removed if necessary in the
  //sbml exporter (see comment in CListOfLayouts::exportToSBML()).
}
예제 #9
0
/*
 * Copy constructor. Creates a copy of this ListOf items.
 */
ListOf::ListOf (const ListOf& orig) : SBase(orig)
{
  mItems.resize( orig.size() );
  transform( orig.mItems.begin(), orig.mItems.end(), mItems.begin(), Clone() );
  connectToChild();
}
예제 #10
0
// [[Rcpp::export]]
SEXP combine_vars(CharacterVector vars, ListOf<IntegerVector> xs) {
  VarList selected(vars.size());
  if (xs.size() == 0)
    return IntegerVector::create();

  // Workaround bug in ListOf<>; can't access attributes
  SEXP raw_names = Rf_getAttrib(xs, Rf_mkString("names"));
  CharacterVector xs_names;
  if (raw_names == R_NilValue) {
    xs_names = CharacterVector(xs.size(), "" );
  } else {
    xs_names = raw_names ;
  }

  // If first component is negative, pre-fill with existing vars
  if (vector_sign(xs[0]) == -1) {
    for (int j = 0; j < vars.size(); ++j) {
      selected.add(j + 1, vars[j]);
    }
  }

  for (int i = 0; i < xs.size(); ++i) {
    IntegerVector x = xs[i];
    if (x.size() == 0) continue;

    int sign = vector_sign(x);

    if (sign == 0)
      stop("Each argument must yield either positive or negative integers");

    if (sign == 1) {
      bool group_named = xs_names[i] != "";
      bool has_names = x.attr("names") != R_NilValue;
      if (group_named) {
        if (x.size() == 1) {
          selected.update(x[0], xs_names[i]);
        } else {
          // If the group is named, children are numbered sequentially
          for (int j = 0; j < x.size(); ++j) {
            std::stringstream out;
            out << xs_names[i] << j + 1;
            selected.update(x[j], out.str());
          }
        }
      } else if (has_names) {
        CharacterVector names = x.names() ;
        for (int j = 0; j < x.size(); ++j) {
          selected.update(x[j], names[j]);
        }
      } else {
        for (int j = 0; j < x.size(); ++j) {
          int pos = x[j];
          if (pos < 1 || pos > vars.size())
            stop("Position must be between 0 and n");

          // Add default name, if not all ready present
          if (!selected.has(pos))
            selected.update(pos, vars[pos - 1]);
        }
      }
    } else {
      for (int j = 0; j < x.size(); ++j) {
        selected.remove(-x[j]);
      }
    }
  }

  return selected;
}
예제 #11
0
//static
void SBMLUtils::collectIds(Model* pModel, std::map<std::string, const SBase*>& ids, std::map<std::string, const SBase*>& metaIds)
{
  if (pModel != NULL)
    {
      // the model itself
      SBase* pSBase = NULL;
      std::string id;

      if (pModel->isSetId())
        {
          id = pModel->getId();

          if (ids.find(id) == ids.end())
            {
              ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
            }
          else
            {
              CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
            }
        }

      if (pModel->isSetMetaId())
        {
          id = pModel->getMetaId();

          if (metaIds.find(id) == metaIds.end())
            {
              metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
            }
          else
            {
              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
            }
        }

      // ListOfFunctionDefinitions
      pSBase = pModel->getListOfFunctionDefinitions();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // all FunctionDefinitions
          unsigned int i, iMax = pModel->getListOfFunctionDefinitions()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getListOfFunctionDefinitions()->get(i);

              if (pSBase->isSetId())
                {
                  id = pSBase->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfUnitDefinition
      pSBase = pModel->getListOfUnitDefinitions();

      if (pSBase != NULL)
        {
          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // all UnitDefinitions
          // for each UnitDefinition: ListOfUnits, each Unit in ListOfUnits
          unsigned int i, iMax = pModel->getListOfUnitDefinitions()->size();

          for (i = 0; i < iMax; ++i)
            {
              /* UnitDefinitions have their ids in a different namespace
                 so we only consider meta ids.
                 */
              UnitDefinition* pUDef = pModel->getUnitDefinition(i);
              assert(pUDef != NULL);

              if (pUDef->isSetMetaId())
                {
                  id = pUDef->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pUDef));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }

              ListOf* pList = pUDef->getListOfUnits();

              if (pList != NULL)
                {
                  if (pList->isSetMetaId())
                    {
                      id = pList->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pList));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }

                  unsigned j, jMax = pList->size();

                  for (j = 0; j < jMax; ++j)
                    {
                      pSBase = pList->get(j);
                      assert(pSBase != NULL);

                      if (pSBase->isSetMetaId())
                        {
                          id = pSBase->getMetaId();

                          if (metaIds.find(id) == metaIds.end())
                            {
                              metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                            }
                        }
                    }
                }
            }
        }

      // ListOfCompartmentTypes
      pSBase = pModel->getListOfCompartmentTypes();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each compartment type
          unsigned int i, iMax = pModel->getListOfCompartmentTypes()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getCompartmentType(i);
              assert(pSBase != NULL);

              if (pSBase->isSetId())
                {
                  id = pSBase->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfSpeciesTypes
      pSBase = pModel->getListOfSpeciesTypes();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each species type
          unsigned int i, iMax = pModel->getListOfSpeciesTypes()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getSpeciesType(i);
              assert(pSBase != NULL);

              if (pSBase->isSetId())
                {
                  id = pSBase->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfCompartments
      pSBase = pModel->getListOfCompartments();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // all compartments
          unsigned int i, iMax = pModel->getListOfCompartments()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getCompartment(i);
              assert(pSBase != NULL);

              if (pSBase->isSetId())
                {
                  id = pSBase->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfSpecies
      pSBase = pModel->getListOfSpecies();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // all species
          unsigned int i, iMax = pModel->getListOfSpecies()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getSpecies(i);
              assert(pSBase != NULL);

              if (pSBase->isSetId())
                {
                  id = pSBase->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfParameters
      pSBase = pModel->getListOfParameters();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each parameter
          unsigned int i, iMax = pModel->getListOfParameters()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getParameter(i);
              assert(pSBase != NULL);

              if (pSBase->isSetId())
                {
                  id = pSBase->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfInitialAssignments
      pSBase = pModel->getListOfInitialAssignments();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each initial assignment
          unsigned int i, iMax = pModel->getListOfInitialAssignments()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getInitialAssignment(i);
              assert(pSBase != NULL);

              // initial assignments have no ids
              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfRules
      pSBase = pModel->getListOfRules();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each rule
          unsigned int i, iMax = pModel->getListOfRules()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getRule(i);
              assert(pSBase != NULL);

              // rules don't have ids
              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfConstraints
      pSBase = pModel->getListOfConstraints();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each constraint
          unsigned int i, iMax = pModel->getListOfConstraints()->size();

          for (i = 0; i < iMax; ++i)
            {
              pSBase = pModel->getConstraint(i);
              assert(pSBase != NULL);

              // constraints don't have ids
              if (pSBase->isSetMetaId())
                {
                  id = pSBase->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }
            }
        }

      // ListOfReactions
      pSBase = pModel->getListOfReactions();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // all reactions
          unsigned int i, iMax = pModel->getListOfReactions()->size();

          for (i = 0; i < iMax; ++i)
            {
              Reaction* pReaction = pModel->getReaction(i);
              assert(pReaction != NULL);

              if (pReaction->isSetId())
                {
                  id = pReaction->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pReaction));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pReaction->isSetMetaId())
                {
                  id = pReaction->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pReaction));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }

              // for each reaction: ListOfSubstrates, each substrate, ListOfProducts, each
              // Product, ListOfModifieres, each modifier, KineticLaw, ListOfparameters,
              // each parameter
              if (pReaction->getListOfReactants() != NULL)
                {
                  pSBase = pReaction->getListOfReactants();

                  if (pSBase->isSetMetaId())
                    {
                      id = pSBase->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }

                  unsigned int j, jMax = pReaction->getListOfReactants()->size();

                  for (j = 0; j < jMax; ++j)
                    {
                      pSBase = pReaction->getReactant(j);
                      assert(pSBase != NULL);

                      // since L2V2 species references can have ids
                      if (pSBase->isSetId())
                        {
                          id = pSBase->getId();

                          if (ids.find(id) == ids.end())
                            {
                              ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                            }
                        }

                      if (pSBase->isSetMetaId())
                        {
                          id = pSBase->getMetaId();

                          if (metaIds.find(id) == metaIds.end())
                            {
                              metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                            }
                        }
                    }
                }

              if (pReaction->getListOfProducts() != NULL)
                {
                  pSBase = pReaction->getListOfProducts();

                  if (pSBase->isSetMetaId())
                    {
                      id = pSBase->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }

                  unsigned int j, jMax = pReaction->getListOfProducts()->size();

                  for (j = 0; j < jMax; ++j)
                    {
                      pSBase = pReaction->getProduct(j);
                      assert(pSBase != NULL);

                      // since L2V2 species references can have ids
                      if (pSBase->isSetId())
                        {
                          id = pSBase->getId();

                          if (ids.find(id) == ids.end())
                            {
                              ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                            }
                        }

                      if (pSBase->isSetMetaId())
                        {
                          id = pSBase->getMetaId();

                          if (metaIds.find(id) == metaIds.end())
                            {
                              metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                            }
                        }
                    }
                }

              if (pReaction->getListOfModifiers() != NULL)
                {
                  pSBase = pReaction->getListOfModifiers();

                  if (pSBase->isSetMetaId())
                    {
                      id = pSBase->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }

                  unsigned int j, jMax = pReaction->getListOfModifiers()->size();

                  for (j = 0; j < jMax; ++j)
                    {
                      pSBase = pReaction->getModifier(j);
                      assert(pSBase != NULL);

                      // since L2V2 species references can have ids
                      if (pSBase->isSetId())
                        {
                          id = pSBase->getId();

                          if (ids.find(id) == ids.end())
                            {
                              ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                            }
                        }

                      if (pSBase->isSetMetaId())
                        {
                          id = pSBase->getMetaId();

                          if (metaIds.find(id) == metaIds.end())
                            {
                              metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                            }
                        }
                    }
                }

              KineticLaw* pKLaw = pReaction->getKineticLaw();

              if (pKLaw != NULL)
                {
                  if (pKLaw->isSetMetaId())
                    {
                      id = pKLaw->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pKLaw));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }

                  pSBase = pKLaw->getListOfParameters();

                  if (pSBase != NULL)
                    {
                      if (pSBase->isSetMetaId())
                        {
                          id = pSBase->getMetaId();

                          if (metaIds.find(id) == metaIds.end())
                            {
                              metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                            }
                        }

                      unsigned int j, jMax = pKLaw->getListOfParameters()->size();

                      for (j = 0; j < jMax; ++j)
                        {
                          pSBase = pKLaw->getParameter(j);
                          assert(pSBase != NULL);

                          // local parameters have their ids in a
                          // different namespace
                          if (pSBase->isSetMetaId())
                            {
                              id = pSBase->getMetaId();

                              if (metaIds.find(id) == metaIds.end())
                                {
                                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                                }
                              else
                                {
                                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                                }
                            }
                        }
                    }
                }
            }
        }

      // ListOfEvents
      pSBase = pModel->getListOfEvents();

      if (pSBase != NULL)
        {
          if (pSBase->isSetId())
            {
              id = pSBase->getId();

              if (ids.find(id) == ids.end())
                {
                  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                }
            }

          if (pSBase->isSetMetaId())
            {
              id = pSBase->getMetaId();

              if (metaIds.find(id) == metaIds.end())
                {
                  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
                }
              else
                {
                  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                }
            }

          // each event
          unsigned int i, iMax = pModel->getListOfEvents()->size();

          for (i = 0; i < iMax; ++i)
            {
              Event* pEvent = pModel->getEvent(i);
              assert(pEvent != NULL);

              if (pEvent->isSetId())
                {
                  id = pEvent->getId();

                  if (ids.find(id) == ids.end())
                    {
                      ids.insert(std::pair<const std::string, const SBase*>(id, pEvent));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
                    }
                }

              if (pEvent->isSetMetaId())
                {
                  id = pEvent->getMetaId();

                  if (metaIds.find(id) == metaIds.end())
                    {
                      metaIds.insert(std::pair<const std::string, const SBase*>(id, pEvent));
                    }
                  else
                    {
                      CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                    }
                }

              // in each event Trigger,Delay,ListOfEventAssignments, each event assignment
              if (pEvent->isSetTrigger())
                {
                  pSBase = pEvent->getTrigger();
                  assert(pSBase != NULL);

                  if (pSBase->isSetMetaId())
                    {
                      id = pSBase->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }
                }

              if (pEvent->isSetDelay())
                {
                  pSBase = pEvent->getDelay();
                  assert(pSBase != NULL);

                  if (pSBase->isSetMetaId())
                    {
                      id = pSBase->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }
                }

              if (pEvent->getListOfEventAssignments() != NULL)
                {
                  pSBase = pEvent->getListOfEventAssignments();

                  if (pSBase->isSetMetaId())
                    {
                      id = pSBase->getMetaId();

                      if (metaIds.find(id) == metaIds.end())
                        {
                          metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                        }
                      else
                        {
                          CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                        }
                    }

                  unsigned int j, jMax = pEvent->getListOfEventAssignments()->size();

                  for (j = 0; j < jMax; ++j)
                    {
                      pSBase = pEvent->getEventAssignment(j);
                      assert(pSBase != NULL);

                      if (pSBase->isSetMetaId())
                        {
                          id = pSBase->getMetaId();

                          if (metaIds.find(id) == metaIds.end())
                            {
                              metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
                            }
                          else
                            {
                              CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
                            }
                        }
                    }
                }
            }
        }
    }
}