Ejemplo n.º 1
0
void NetworkModel::add_species_attribute(const Species& sp)
{
    if (has_species_attribute(sp))
    {
        throw AlreadyExists("species already exists");
    }
    species_attributes_.push_back(sp);
}
Ejemplo n.º 2
0
OptionBinds::Item & OptionBinds::add(const std::string & id, Option & option)
{
    auto item = items.find(id);
    if (item != items.end())
        throw AlreadyExists(id);
    auto res = items.emplace(id, Item(option));
    return res.first->second;
}
Ejemplo n.º 3
0
void NetworkModel::add_species(const Species& sp)
{
    if (has_species(sp))
    {
        throw AlreadyExists("species already exists");
    }
    species_.push_back(sp);
    dirty_ = true;
}
Ejemplo n.º 4
0
OptionBinds::Item & OptionBinds::add(const std::string & id, Option & option,
    Item::NewStringFunc && newString, Item::GetValueStringFunc && getValueString, bool addValue)
{
    auto item = items.find(id);
    if (item != items.end())
        throw AlreadyExists(id);
    auto res = items.emplace(id, Item(option, std::move(newString), std::move(getValueString), addValue));
    return res.first->second;
}
Ejemplo n.º 5
0
Channel* ChannelRegistry::add(const std::string& channelName) {
	ND_DEBUG("[ChannelRegistry] Request to add new Channel named %s.\n", channelName.c_str());

	if ( exists(channelName) ) throw AlreadyExists(AlreadyExists::msg("channel", channelName));

	Channel* channelPtr = new Channel(channelName);
	if ( !channelPtr ) throw OutOfMemory("ChannelRegistry::autoLoad: Unable to allocate memory for new Channel.");
	_channels[channelName] = channelPtr;

	return (channelPtr);
}
Ejemplo n.º 6
0
void CompartmentSpaceVectorImpl::reserve_species(const Species& sp)
{
    species_map_type::const_iterator i(index_map_.find(sp));
    if (i != index_map_.end())
    {
        throw AlreadyExists("Species already exists");
    }

    index_map_.insert(std::make_pair(sp, num_molecules_.size()));
    species_.push_back(sp);
    num_molecules_.push_back(0);
}
Ejemplo n.º 7
0
void NetworkModel::add_reaction_rule(const ReactionRule& rr)
{
    reaction_rule_container_type::const_iterator
        i(std::find(reaction_rules_.begin(), reaction_rules_.end(), rr));
    if (i != reaction_rules_.end())
    {
        throw AlreadyExists("reaction rule already exists");
    }

    reaction_rules_map_[rr.reactants()].insert(reaction_rules_.size());
    reaction_rules_.push_back(rr);
    dirty_ = true;
}
Ejemplo n.º 8
0
void FileSystem::appendToNode(FileNode* new_node, FileNode* parent_node) {
  pair<FileMap::iterator, bool> fmap_ret;

  pthread_mutex_lock(&fmap_mux);
    fmap_ret = file_map.insert(pair<const char*, FileNode*>(new_node->pathname, new_node));
  pthread_mutex_unlock(&fmap_mux);

  if (fmap_ret.second == false) {
    throw AlreadyExists(new_node);
  }

  parent_node->addChild(new_node);
  new_node->parent = parent_node;
  return;
}
Ejemplo n.º 9
0
			void RegexpMatcherManager::Add (const QString& title, const QString& body)
			{
				if (!IsRegexpValid (title) || !IsRegexpValid (body))
					throw Malformed ("Regexp is malformed");
			
				items_t::const_iterator found =
					std::find_if (Items_.begin (), Items_.end (),
							boost::bind (boost::function<bool (const RegexpMatcherManager::RegexpItem&,
									const QString)> (&RegexpMatcherManager::RegexpItem::IsEqual),
								_1, title));
			
				if (found != Items_.end ())
					throw AlreadyExists ("Regexp user tries to add already exists in the RegexpMatcherManager");
			
				beginInsertRows (QModelIndex (), rowCount (), rowCount ());
				Items_.push_back (RegexpItem (title, body));
				endInsertRows ();
			
				ScheduleSave ();
			}
Ejemplo n.º 10
0
	void TypeCollection::addType( std::shared_ptr< TypeMetainfoImpl_I > type )
	{
		auto it = std::find_if( mTypes.begin(), mTypes.end(), TypeByName( type->getId()->getName() ) );
		if ( it != mTypes.end() )
		{
			std::ostringstream msg;
			msg << "type " << type->getId()->getName() << " already exists" << std::endl;
			throw AlreadyExists( msg.str() );
		}

		if ( !type->isBasicType() )
		{
			auto custom = std::static_pointer_cast< const CustomTypeMetainfoImpl >( type );
			auto connection = custom->registerToDestroyed( std::bind( &TypeCollection::typeDestroyed, this, std::placeholders::_1 ) );
			mTypes.push_back( std::make_pair( connection, type ) );
		}
		else
		{
			mTypes.push_back( std::make_pair( Connection(), type ) );
		}
	}
Ejemplo n.º 11
0
/* FileSystem::append */
void FileSystem::append(FileNode* new_node) {
  pair<FileMap::iterator, bool> fmap_ret;

  pthread_mutex_lock(&fmap_mux);
    fmap_ret = file_map.insert(pair<const char*, FileNode*>(new_node->pathname, new_node));
  pthread_mutex_unlock(&fmap_mux);

  if (fmap_ret.second == false) {
    throw AlreadyExists(fmap_ret.first->second);
  }

  /* Aktualizace rodiřů/potomků - vyhledání adresáře obsahujícího
   * přidávaný soubor, pokud není nalezen vytvoříme ho.
   * Přidáme aktuální soubor do seznamu s potomky u rodiče a aktuálnímu
   * uzlu nastavíme ukazatel na nadřazený uzel. */


  FileNode* parent_node;
  char parent_name[PATH_MAX];
  /* Pokud jmeno zacina tam kde cesta, nachazi se v korenovem adresari */
  if (new_node->pathname == new_node->name_ptr)
    parent_node = root_node;
  else {
    /* Na chvili retezec rozsekneme */
    *(new_node->name_ptr-1) = '\0';
    strcpy(parent_name, new_node->pathname);
    *(new_node->name_ptr-1) = '/';
    parent_node = find(parent_name);
    if (parent_node == NULL) {
      parent_node = new FileNode(parent_name, NULL, FileNode::DIR_NODE);
      append(parent_node);
    }
  }

  new_node->parent = parent_node;
  parent_node->addChild(new_node);
}
///////////////////////////////////////////////////////////////////////////////////////////
// BuildStripifyInfo()
//
// Builds the list of all face and edge infos
//
void NvStripifier::BuildStripifyInfo(NvFaceInfoVec &faceInfos, NvEdgeInfoVec &edgeInfos,
									 const unsigned short maxIndex)
{
	// reserve space for the face infos, but do not resize them.
	int numIndices = indices.size();
	faceInfos.reserve(numIndices / 3);
	
	// we actually resize the edge infos, so we must initialize to NULL
	edgeInfos.resize(maxIndex + 1);
	for (unsigned short i = 0; i < maxIndex + 1; i++)
		edgeInfos[i] = NULL;
	
	// iterate through the triangles of the triangle list
	int numTriangles = numIndices / 3;
	int index        = 0;
	bool bFaceUpdated[3];

	for (int i = 0; i < numTriangles; i++)
	{	
		bool bMightAlreadyExist = true;
		bFaceUpdated[0] = false;
		bFaceUpdated[1] = false;
		bFaceUpdated[2] = false;

		// grab the indices
		int v0 = indices[index++];
		int v1 = indices[index++];
		int v2 = indices[index++];

		//we disregard degenerates
		if(IsDegenerate(v0, v1, v2))
			continue;
		
		// create the face info and add it to the list of faces, but only if this exact face doesn't already 
		//  exist in the list
		NvFaceInfo *faceInfo = new NvFaceInfo(v0, v1, v2);
		
		// grab the edge infos, creating them if they do not already exist
		NvEdgeInfo *edgeInfo01 = FindEdgeInfo(edgeInfos, v0, v1);
		if (edgeInfo01 == NULL)
		{
			//since one of it's edges isn't in the edge data structure, it can't already exist in the face structure
			bMightAlreadyExist = false;

			// create the info
			edgeInfo01 = new NvEdgeInfo(v0, v1);
			
			// update the linked list on both 
			edgeInfo01->m_nextV0 = edgeInfos[v0];
			edgeInfo01->m_nextV1 = edgeInfos[v1];
			edgeInfos[v0] = edgeInfo01;
			edgeInfos[v1] = edgeInfo01;
			
			// set face 0
			edgeInfo01->m_face0 = faceInfo;
		}
		else 
		{
			if (edgeInfo01->m_face1 != NULL)
			{
				printf("BuildStripifyInfo: > 2 triangles on an edge... uncertain consequences\n");
			}
			else
			{
				edgeInfo01->m_face1 = faceInfo;
				bFaceUpdated[0] = true;
			}
		}
		
		// grab the edge infos, creating them if they do not already exist
		NvEdgeInfo *edgeInfo12 = FindEdgeInfo(edgeInfos, v1, v2);
		if (edgeInfo12 == NULL)
		{
			bMightAlreadyExist = false;
			
			// create the info
			edgeInfo12 = new NvEdgeInfo(v1, v2);
			
			// update the linked list on both 
			edgeInfo12->m_nextV0 = edgeInfos[v1];
			edgeInfo12->m_nextV1 = edgeInfos[v2];
			edgeInfos[v1] = edgeInfo12;
			edgeInfos[v2] = edgeInfo12;
			
			// set face 0
			edgeInfo12->m_face0 = faceInfo;
		}
		else 
		{
			if (edgeInfo12->m_face1 != NULL)
			{
				printf("BuildStripifyInfo: > 2 triangles on an edge... uncertain consequences\n");
			}
			else
			{
				edgeInfo12->m_face1 = faceInfo;
				bFaceUpdated[1] = true;
			}
		}
		
		// grab the edge infos, creating them if they do not already exist
		NvEdgeInfo *edgeInfo20 = FindEdgeInfo(edgeInfos, v2, v0);
		if (edgeInfo20 == NULL)
		{
			bMightAlreadyExist = false;

			// create the info
			edgeInfo20 = new NvEdgeInfo(v2, v0);
			
			// update the linked list on both 
			edgeInfo20->m_nextV0 = edgeInfos[v2];
			edgeInfo20->m_nextV1 = edgeInfos[v0];
			edgeInfos[v2] = edgeInfo20;
			edgeInfos[v0] = edgeInfo20;
			
			// set face 0
			edgeInfo20->m_face0 = faceInfo;
		}
		else 
		{
			if (edgeInfo20->m_face1 != NULL)
			{
				printf("BuildStripifyInfo: > 2 triangles on an edge... uncertain consequences\n");
			}
			else
			{
				edgeInfo20->m_face1 = faceInfo;
				bFaceUpdated[2] = true;
			}
		}

		if(bMightAlreadyExist)
		{
			if(!AlreadyExists(faceInfo, faceInfos))
				faceInfos.push_back(faceInfo);
			else
			{
				delete faceInfo;

				//cleanup pointers that point to this deleted face
				if(bFaceUpdated[0])
					edgeInfo01->m_face1 = NULL;
				if(bFaceUpdated[1])
					edgeInfo12->m_face1 = NULL;
				if(bFaceUpdated[2])
					edgeInfo20->m_face1 = NULL;
			}
		}
		else
		{
			faceInfos.push_back(faceInfo);
		}

	}
}
Ejemplo n.º 13
0
///////////////////////////////////////////////////////////////////////////////////////////
// BuildStripifyInfo()
//
// Builds the list of all face and edge infos
//
void NvStripifier::BuildStripifyInfo(NvFaceInfoVec &faceInfos, NvEdgeInfoVec &edgeInfos){
	
	// reserve space for the face infos, but do not resize them.
	int numIndices = indices.size();
	faceInfos.reserve(numIndices);
	
	// we actually resize the edge infos, so we must initialize to NULL
	edgeInfos.resize (numIndices);
	for (int i = 0; i < numIndices; i++)
		edgeInfos[i] = NULL;
	
	// iterate through the triangles of the triangle list
	int numTriangles = numIndices / 3;
	int index        = 0;
	for (u32 i = 0; i < numTriangles; i++)
	{	
		// grab the indices
		int v0 = indices[index++];
		int v1 = indices[index++];
		int v2 = indices[index++];
		
		// create the face info and add it to the list of faces, but only if this exact face doesn't already 
		//  exist in the list
		NvFaceInfo *faceInfo = xr_new<NvFaceInfo>(v0, v1, v2);
		if(!AlreadyExists(faceInfo, faceInfos))
		{
			faceInfos.push_back(faceInfo);
			
			// grab the edge infos, creating them if they do not already exist
			NvEdgeInfo *edgeInfo01 = FindEdgeInfo(edgeInfos, v0, v1);
			if (edgeInfo01 == NULL){
				
				// create the info
				edgeInfo01 = xr_new<NvEdgeInfo>(v0, v1);
				
				// update the linked list on both 
				edgeInfo01->m_nextV0 = edgeInfos[v0];
				edgeInfo01->m_nextV1 = edgeInfos[v1];
				edgeInfos[v0] = edgeInfo01;
				edgeInfos[v1] = edgeInfo01;
				
				// set face 0
				edgeInfo01->m_face0 = faceInfo;
			}
			else {
				if (edgeInfo01->m_face1 != NULL)	;
					//Msg("! WARNING: BuildStripifyInfo: > 2 triangles on an edge... uncertain consequences");
				else
					edgeInfo01->m_face1 = faceInfo;
			}
			
			// grab the edge infos, creating them if they do not already exist
			NvEdgeInfo *edgeInfo12 = FindEdgeInfo(edgeInfos, v1, v2);
			if (edgeInfo12 == NULL){
				
				// create the info
				edgeInfo12 = xr_new<NvEdgeInfo> (v1, v2);
				
				// update the linked list on both 
				edgeInfo12->m_nextV0 = edgeInfos[v1];
				edgeInfo12->m_nextV1 = edgeInfos[v2];
				edgeInfos[v1] = edgeInfo12;
				edgeInfos[v2] = edgeInfo12;
				
				// set face 0
				edgeInfo12->m_face0 = faceInfo;
			}
			else {
				if (edgeInfo12->m_face1 != NULL)	;
					//Msg("! WARNING: BuildStripifyInfo: > 2 triangles on an edge... uncertain consequences");
				else
					edgeInfo12->m_face1 = faceInfo;
			}
			
			// grab the edge infos, creating them if they do not already exist
			NvEdgeInfo *edgeInfo20 = FindEdgeInfo(edgeInfos, v2, v0);
			if (edgeInfo20 == NULL){
				
				// create the info
				edgeInfo20 = xr_new<NvEdgeInfo>(v2, v0);
				
				// update the linked list on both 
				edgeInfo20->m_nextV0 = edgeInfos[v2];
				edgeInfo20->m_nextV1 = edgeInfos[v0];
				edgeInfos[v2] = edgeInfo20;
				edgeInfos[v0] = edgeInfo20;
				
				// set face 0
				edgeInfo20->m_face0 = faceInfo;
			}
			else {
				if (edgeInfo20->m_face1 != NULL)	;
					//Msg("! WARNING: BuildStripifyInfo: > 2 triangles on an edge... uncertain consequences");
				else
					edgeInfo20->m_face1 = faceInfo;
			}
			
		}
	}
}