Example #1
0
vertex_id Network::addVertex() {
	if (isNamed()) throw OperationNotSupportedException("Cannot add an anonymous vertex to a named network");
	max_vertex_id++;
	vertex_id new_vertex_id = max_vertex_id;
	vertexes.insert(new_vertex_id);
	return new_vertex_id;
}
Example #2
0
bool Network::deleteVertex(vertex_id vid) {
	if (!containsVertex(vid)) return false;
	std::set<vertex_id> in = getInNeighbors(vid);
	std::set<vertex_id> out = getOutNeighbors(vid);

	// removing adjacent edges
	for (std::set<vertex_id>::iterator it=in.begin(); it!=in.end(); it++)
		deleteEdge(*it,vid);
	for (std::set<vertex_id>::iterator it=out.begin(); it!=out.end(); it++)
		deleteEdge(vid,*it);

	// removing the vertex
	vertexes.erase(vid);
	if (isNamed()) {
		// some more structures to empty
		const std::string& vertex_name=vertex_id_to_name[vid];
		vertex_id_to_name.erase(vid);
		vertex_name_to_id.erase(vertex_name);
	}
	// remove attribute values
	for (std::map<std::string,std::map<vertex_id,std::string> >::iterator it=vertex_string_attribute.begin(); it!=vertex_string_attribute.end(); it++)
		vertex_string_attribute[it->first].erase(vid);
	for (std::map<std::string,std::map<vertex_id,double> >::iterator it=vertex_numeric_attribute.begin(); it!=vertex_numeric_attribute.end(); it++)
		vertex_numeric_attribute[it->first].erase(vid);
	return true;
}
Example #3
0
void gcore::Pipe::close() {
  if (isNamed() && isOwned()) {
#ifndef _WIN32
    gcore::String path = "/tmp/" + mName;
    closeRead();
    closeWrite();
    unlink(path.c_str());
#else
    if (mConnected) {
      FlushFileBuffers(mDesc[1]);
      DisconnectNamedPipe(mDesc[0]);
    }
    closeRead();
    closeWrite();
#endif
  } else {
    closeRead();
    closeWrite();
  }
  mName = "";
  mOwn = false;
#ifdef _WIN32
  mConnected = false;
#endif
}
Example #4
0
edge_id Network::addEdge(const std::string& vertex_name1, const std::string& vertex_name2) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	//std::cout << "Edge: " << vertex_name1 << " " << vertex_name_to_id[vertex_name1]
	//<< " " << vertex_name2 << " " << vertex_name_to_id[vertex_name2] << std::endl;
	return addEdge(vertex_name_to_id[vertex_name1],vertex_name_to_id[vertex_name2]);
}
Example #5
0
std::set<std::string> Network::getInNeighbors(const std::string& vertex_name) const  {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name)) throw ElementNotFoundException("Vertex " + vertex_name);
	std::set<std::string> neighbors;
	std::set<vertex_id> tmp_id_result = getInNeighbors(vertex_name_to_id.at(vertex_name));
	for (std::set<vertex_id>::iterator it=tmp_id_result.begin(); it!=tmp_id_result.end(); it++)
		neighbors.insert(vertex_id_to_name.at(*it));
	return neighbors;
}
Example #6
0
vertex_id Network::addVertex(const std::string& vertex_name) {
	if (containsVertex(vertex_name)) throw DuplicateElementException("Vertex " + vertex_name + " already exists");
	if (!isNamed()) throw OperationNotSupportedException("Cannot add a named vertex to an unnamed network");
	max_vertex_id++;
	vertex_id new_vertex_id = max_vertex_id;
	vertexes.insert(new_vertex_id);
	vertex_id_to_name[new_vertex_id] = vertex_name;
	vertex_name_to_id[vertex_name] = new_vertex_id;
	return new_vertex_id;
}
Example #7
0
void XMLElement::assertName(const std::string& name) const {
    if (!isNamed(name)) {
        std::string tmp;
        getName(tmp);
        throw std::invalid_argument("XMLElement::assertName() '" + name
                + "' != '"
                + tmp
                + "'");
    }
}
Example #8
0
/* Throws std::invalid_argument if argument is invalid */
void XMLElement::assertName(const std::string& name) const {
    if (!isNamed(name)) {
        throw std::invalid_argument("XMLElement::assertName() '" + name
                + "' != '"
#ifdef PUGIXML
                + nodePtr.name()
#else
                + reinterpret_cast<const char *> (nodePtr->name)
#endif
                + "'");
    }
}
Example #9
0
int gcore::Pipe::read(String &str, bool retryOnInterrupt) const {
  char rdbuf[256];

  if (canRead()) {
#ifndef _WIN32
    int bytesRead = ::read(mDesc[0], rdbuf, 255);
    while (bytesRead == -1 && (errno == EAGAIN || (errno == EINTR && retryOnInterrupt))) {
      bytesRead = ::read(mDesc[0], rdbuf, 255);
    }
    if (bytesRead >= 0) {
      rdbuf[bytesRead] = '\0';
      str = rdbuf;
    }
    return bytesRead;
#else
    bool namedPipeServer = (isNamed() && isOwned());
    if (namedPipeServer && !mConnected) {
      if (ConnectNamedPipe(mDesc[0], NULL)) {
        mConnected = true;
      } else {
        return -1;
      }
    }
    DWORD bytesRead = 0;
    BOOL rv = ReadFile(mDesc[0], rdbuf, 255, &bytesRead, NULL);
    while (rv == FALSE) {
      DWORD lastErr = GetLastError();
      if (lastErr == ERROR_IO_PENDING) {
        rv = ReadFile(mDesc[0], rdbuf, 255, &bytesRead, NULL);
      } else {
        if (namedPipeServer) {
          DisconnectNamedPipe(mDesc[0]);
          mConnected = false;
        }
        if (lastErr == ERROR_HANDLE_EOF || lastErr == ERROR_BROKEN_PIPE) {
          rv = TRUE;
          bytesRead = 0;
        }
        break;
      }
    }
    if (rv) {
      rdbuf[bytesRead] = '\0';
      str = rdbuf;
      return bytesRead;
    }
#endif
  }

  str = "";
  return -1;
}
Example #10
0
void rename_obs (const Reorder::Reordering<Ob>& o_order)
{//moves names and reps
    for (Ob::sparse_iterator iter=Ob::sbegin(), end=Ob::send();
            iter!=end; ++iter) {
        Ob old_ob = *iter;

        //move name
        if (isNamed(old_ob)) {
            Ob new_ob = o_order.old2new(old_ob);
            old_ob(NAME)->move_to_tandem(new_ob);
        }

        //move rep
        Ob old_rep = old_ob(REP);
        Ob new_rep = o_order.old2new(old_rep);
        old_ob(REP) = new_rep;
    }
}
Example #11
0
int gcore::Pipe::write(const char *buffer, int size) const {
  if (canWrite()) {
#ifndef _WIN32
    int bytesToWrite = size;
    int rv = ::write(mDesc[1], buffer, bytesToWrite);
    while (rv == -1 && errno == EAGAIN) {
      rv = ::write(mDesc[1], buffer, bytesToWrite);
    }
    return rv;
#else
    bool namedPipeServer = (isNamed() && isOwned());
    if (namedPipeServer && !mConnected) {
      if (ConnectNamedPipe(mDesc[1], NULL)) {
        mConnected = true;
      } else {
        return -1;
      }
    }
    DWORD bytesToWrite = (DWORD)size;
    DWORD bytesWritten = 0;
    BOOL rv = WriteFile(mDesc[1], buffer, bytesToWrite, &bytesWritten, NULL);
    while (rv == FALSE) {
      DWORD lastErr = GetLastError();
      if (lastErr == ERROR_IO_PENDING) {
        rv = WriteFile(mDesc[1], buffer, bytesToWrite, &bytesWritten, NULL);
      } else {
        if (namedPipeServer) {
          DisconnectNamedPipe(mDesc[1]);
          mConnected = false;
        }
        break;
      }
    }
    return (rv == TRUE ? bytesWritten : -1);
#endif
  }
return -1;
}
Example #12
0
		const Node<Type>& TypeVar::namedType() const {
			assert(isNamed());
			return namedVar_.type;
		}
Example #13
0
		const String& TypeVar::name() const {
			assert(isNamed());
			return namedVar_.name;
		}
Example #14
0
edge_id Network::addEdge(const std::string& vertex_name1, const std::string& vertex_name2, double weight) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	return addEdge(vertex_name_to_id[vertex_name1],vertex_name_to_id[vertex_name2], weight);
}
Example #15
0
		bool TypeVar::isFinal() const {
			assert(isNamed());
			return namedVar_.isFinal;
		}
Example #16
0
void Network::setStringEdgeAttribute(const std::string& vertex_name1, const std::string& vertex_name2, const std::string& attribute_name, const std::string& val) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	setStringEdgeAttribute(vertex_name_to_id.at(vertex_name1), vertex_name_to_id.at(vertex_name2), attribute_name, val);
}
Example #17
0
void Network::setStringVertexAttribute(const std::string& vertex_name, const std::string& attribute_name, const std::string& val) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	setStringVertexAttribute(vertex_name_to_id[vertex_name], attribute_name, val);
}
Example #18
0
bool Network::deleteVertex(const std::string& vertex_name) {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name)) return false;
	deleteVertex(vertex_name_to_id[vertex_name]);
	return true;
}
Example #19
0
		void TypeVar::setFinal() {
			assert(isNamed());
			namedVar_.isFinal = true;
		}
Example #20
0
		bool TypeVar::isOverrideConst() const {
			assert(isNamed());
			return namedVar_.isOverrideConst;
		}
Example #21
0
		void TypeVar::setOverrideConst() {
			assert(isNamed());
			namedVar_.isOverrideConst = true;
		}
Example #22
0
vertex_id Network::getVertexId(const std::string& vertex_name) const  {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name)) throw ElementNotFoundException("Vertex " + vertex_name);
	return vertex_name_to_id.at(vertex_name);
}
Example #23
0
		bool TypeVar::isUnused() const {
			assert(isNamed());
			return namedVar_.isUnused;
		}
Example #24
0
bool Network::containsEdge(const std::string& vertex_name1, const std::string& vertex_name2) const {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named edge in an unnamed network");
	if (!containsVertex(vertex_name1)) return false;
	if (!containsVertex(vertex_name2)) return false;
	return containsEdge(vertex_name_to_id.at(vertex_name1),vertex_name_to_id.at(vertex_name2));
}
Example #25
0
double Network::getNumericEdgeAttribute(const std::string& vertex_name1, const std::string& vertex_name2, const std::string& attribute_name) const {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vertex_name1)) throw ElementNotFoundException("Vertex " + vertex_name1);
	if (!containsVertex(vertex_name2)) throw ElementNotFoundException("Vertex " + vertex_name2);
	return getNumericEdgeAttribute(vertex_name_to_id.at(vertex_name1), vertex_name_to_id.at(vertex_name2), attribute_name);
}
Example #26
0
std::string Network::getVertexName(vertex_id vid) const  {
	if (!isNamed()) throw OperationNotSupportedException("Cannot reference a named vertex in an unnamed network");
	if (!containsVertex(vid)) throw ElementNotFoundException("Vertex " + std::to_string(vid));
	return vertex_id_to_name.at(vid);
}
Example #27
0
		void TypeVar::setUnused() {
			assert(isNamed());
			namedVar_.isUnused = true;
		}