bool DirectedGraph::addEdge(int fromNodeId, int toNodeId) {
	if (hasEdge(fromNodeId, toNodeId))
		return false;

	if (!hasNode(fromNodeId))
		addNode(fromNodeId);
	if (!hasNode(toNodeId))
		addNode(toNodeId);
	ListType* fromNeighbors = inNeighborsTable[toNodeId];
	fromNeighbors->push_back(fromNodeId);
	ListType* toNeighbors = outNeighborsTable[fromNodeId];
	toNeighbors->push_back(toNodeId);
	edgeCount++;
	return true;
}
Beispiel #2
0
static void addTypeToList(const Root & type, ListType & typeList)
{
    typeList.push_back(type->getId());
    Element children;
    if (type->copyAttr("children", children) != 0) {
        return;
    }
    if (!children.isList()) {
        log(ERROR, compose("Type %1 children attribute has type %2 instead of "
                           "string.", type->getId(),
                           Element::typeName(children.getType())));
        return;
    }
    ListType::const_iterator I = children.List().begin();
    ListType::const_iterator Iend = children.List().end();
    for (; I != Iend; ++I) {
        Root child = Inheritance::instance().getClass(I->asString());
        if (!child.isValid()) {
            log(ERROR, compose("Unable to find %1 in inheritance table",
                               I->asString()));
            continue;
        }
        addTypeToList(child, typeList);
    }
}
Beispiel #3
0
Atlas::Message::Element EntityEditor::createPosition2dElement()
{
	ListType list;
	list.push_back(createFloatElement());
	list.push_back(createFloatElement());
	return Element(list);
}
Beispiel #4
0
ListType CyPy_Element::sequenceAsElement(const Py::Sequence& sequence)
{
    ListType res;
    for (auto& entry : sequence) {
        res.push_back(asElement(entry));
    }
    return res;
}
Beispiel #5
0
ListType CyPy_Element::listAsElement(const Py::List& list)
{
    ListType res;
    for (auto& entry : list) {
        res.push_back(asElement(entry));
    }
    return res;
}
Beispiel #6
0
int PyListObject_asElement(PyObject * list, ListType & res)
{
    PyMessage * item;
    int len = PyList_Size(list);
    for(int i = 0; i < len; i++) {
        item = (PyMessage *)PyList_GetItem(list, i);
        if (PyMessage_Check(item)) {
            res.push_back(*(item->m_obj));
        } else {
            Element o;
            if (PyObject_asMessageElement((PyObject*)item, o) == 0) {
                res.push_back(o);
            } else {
                debug( std::cout << "Python to atlas conversion failed on element " << i << " of list" << std::endl << std::flush; );
                return -1;
            }
        }
    }
Beispiel #7
0
int Gear_OscInput::configuredOscHandler(const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
{
	Gear_OscInput *gearOscInput = (Gear_OscInput*)user_data;
	std::cout << "Osc message received : " << std::endl;
	std::cout << "path: " << path << std::endl;
	
	OscMessageType message;
	ListType list;
	
	message.setPath(std::string(path));

	for (int i=0; i<argc; i++) 
	{
		std::cout << "arg " << i << " " << types[i] << std::endl;
		if (types[i]==LO_FLOAT) 
		{	
			ValueType *valuet = new ValueType();
			valuet->setValue((float)argv[i]->f);
			list.push_back(valuet);
		} else if (types[i]==LO_INT32) 
		{
			ValueType *valuet = new ValueType();
			valuet->setValue((float)argv[i]->i32);
			list.push_back(valuet);			
		} else if (types[i]==LO_DOUBLE)
		{
			ValueType *valuet = new ValueType();
			valuet->setValue((float)argv[i]->d);
			list.push_back(valuet);			
		} else if (types[i]==LO_STRING)
		{
			StringType *stringt = new StringType();
			stringt->setValue(argv[i]->s);
			list.push_back(stringt);			
		}	
	}	
	
	message.setArgs(list);

	ScopedLock scopedLock(gearOscInput->_mutex);
	gearOscInput->_messages.push_back(message);	
	
	return 0;
}
Beispiel #8
0
void Player::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
{
    Account::addToEntity(ent);
    ListType typeList;
    std::set<std::string>::const_iterator I = Player::playableTypes.begin();
    std::set<std::string>::const_iterator Iend = Player::playableTypes.end();
    for (; I != Iend; ++I) {
        typeList.push_back(Element(*I));
    }
    ent->setAttr("character_types", typeList);
}
Beispiel #9
0
Element CyPy_Element::asElement(const Py::Object& o)
{
    if (o.isLong()) {
        return Py::Long(o).as_long();
    }
    if (o.isFloat()) {
        return Py::Float(o).as_double();
    }
    if (o.isString()) {
        return o.as_string();
    }
    if (CyPy_ElementList::check(o)) {
        return CyPy_ElementList::value(o);
    }
    if (CyPy_ElementMap::check(o)) {
        return CyPy_ElementMap::value(o);
    }
    if (CyPy_Operation::check(o)) {
        return CyPy_Operation::value(o)->asMessage();
    }
    if (CyPy_RootEntity::check(o)) {
        return CyPy_RootEntity::value(o)->asMessage();
    }
    if (CyPy_Root::check(o)) {
        return CyPy_Root::value(o)->asMessage();
    }
    if (CyPy_Oplist::check(o)) {
        auto& oplist = CyPy_Oplist::value(o);
        ListType list;
        for (auto& entry : oplist) {
            list.push_back(entry->asMessage());
        }
        return list;
    }
    if (CyPy_Location::check(o)) {
        MapType map;
        CyPy_Location::value(o).addToMessage(map);
        return map;
    }
    if (o.isList()) {
        return listAsElement(Py::List(o));
    }
    if (o.isDict()) {
        return dictAsElement(Py::Dict(o));
    }
    if (o.isSequence()) {
        return sequenceAsElement(Py::Sequence(o));
    }
    if (o.isNone()) {
        return Element();
    }
    throw Py::TypeError(String::compose("Contained object (of type %1) could not be converted to an Element.", o.type().as_string()));
}
Beispiel #10
0
void Gear_PackList::runVideo()
{
  ListType *listType = _LIST_OUT->type();
  
  if (_LIST_IN->connected())
    listType->assign(_LIST_IN->type()->begin(), _LIST_IN->type()->end());
  else 
    clearList();  

  listType->push_back(_STR1->type());

}
Beispiel #11
0
bool ParseResult::append(ParseResult &&p) {
  ListType* vect;
  if (isEmpty()) {
    assert(result_ == nullptr);
    resultKind_ = p.resultKind_;
    isList_ = true;
    vect = new ListType();
    result_ = vect;
  }
  else {
    assert(isList_);
    vect = reinterpret_cast<ListType*>(result_);
  }
  if (p.isList_ || p.resultKind_ != resultKind_)
    return false;

  vect->push_back(p.result_);
  p.release();
  return true;
}
Beispiel #12
0
void Gear_UnpackList::runVideo()
{
  //std::cout << name() << "::: size:: " << _LIST_IN->type()->size() << std::endl;
  if (!_LIST_IN->connected() ||
      _LIST_IN->type()->empty())
  {    
    _LIST_OUT->sleeping(true); // TODO: the sleeping mechanism just doesn't work
    return;
  }

  _LIST_OUT->sleeping(false);

  ListType *listType = _LIST_OUT->type();
  const AbstractType *type = _LIST_IN->type()->front();

  // XXX Maybe there's a more efficient way than clearing/populating each time but this
  // is safe memory-wise.
  clearList();

  // Copy
  const ListType* inputList = _LIST_IN->type();
  for(ListType::const_iterator it=inputList->begin() + 1; it!=inputList->end(); ++it)
    listType->push_back( (*it)->clone() );

  //std::cout << "got something " << type->typeName() << std::endl;
  //for (ListType::const_iterator it = _LIST_IN->type()->begin(); it != _LIST_IN->type()->end(); ++it)
  //listType->assign(_LIST_IN->type()->begin(), _LIST_IN->type()->end());
  
  if ((_STR_OUT->connected()) && type->typeName() == StringType().typeName())
  {
    //std::cout << "sending str out: " << ((StringType*)type)->value() << std::endl;
    _STR_OUT->type()->copyFrom(*type);
    return;
  }
    
  else if ((_VAL_OUT->connected()) && type->typeName() == ValueType().typeName())
  {
    //std::cout << "sending val out: " << ((ValueType*)type)->value() << std::endl;
    _VAL_OUT->type()->copyFrom(*type);
    return;
  }

  else if ((_ENUM_OUT->connected()) && type->typeName() == EnumType().typeName())
  {
    //std::cout << "sending val out: " << ((ValueType*)type)->value() << std::endl;
    _ENUM_OUT->type()->copyFrom(*type);
    return;
  }

  else if ((_CHANNEL_OUT->connected()) && type->typeName() == VideoChannelType().typeName())
  {
    //std::cout << "sending val out: " << ((ValueType*)type)->value() << std::endl;
    _CHANNEL_OUT->type()->copyFrom(*type);
    return;
  }


  else if ((_VIDEO_OUT->connected()) && type->typeName() == VideoRGBAType().typeName())
  {
    //std::cout << "sending val out: " << ((ValueType*)type)->value() << std::endl;
    _VIDEO_OUT->type()->copyFrom(*type);
    return;
  }

  else if ((_AREA_OUT->connected()) && type->typeName() == AreaType().typeName())
  {
    //std::cout << "sending val out: " << ((ValueType*)type)->value() << std::endl;
    _AREA_OUT->type()->copyFrom(*type);
    return;
  }
}
Beispiel #13
0
int main(int argc, char** argv)
{
    std::string atlas_xml_path;
    char * srcdir_env = getenv("srcdir");
    if (srcdir_env != 0) {
        atlas_xml_path = srcdir_env;
        atlas_xml_path += "/";
    }
    atlas_xml_path += "../../protocol/spec/atlas.xml";
    try {
	Atlas::Objects::loadDefaults(atlas_xml_path);
    } catch(Atlas::Objects::DefaultLoadingException e) {
	std::cout << "DefaultLoadingException: "
             << e.getDescription() << std::endl;
    }
    Root root = Atlas::Objects::objectDefinitions.find("root")->second;
    Root root_inst;
    root_inst->setAttr("id", std::string("root_instantiation"));
    assert(root->getAttr("id").asString() == "root");
    assert(root_inst->getAttr("id").asString() == "root_instantiation");
    assert(root->getAttr("parents").asList().size() == 0);
    assert(root_inst->getAttr("parents").asList().size() == 1);
    assert((*root_inst->getAttr("parents").asList().begin()).asString() ==
            "root");

    Look look = smart_dynamic_cast<Look>(objectDefinitions.find("look")->second);
    Look look_inst;
    look_inst->setAttr("id", std::string("look_instantiation"));
    assert(look->getAttr("id").asString() == "look");
    assert(look_inst->getAttr("id").asString() == "look_instantiation");
    assert(look->getAttr("parents").asList().size() == 1);
    assert((*look->getAttr("parents").asList().begin()).asString() ==
            "perceive");
    assert(look_inst->getAttr("parents").asList().size() == 1);
    assert((*look_inst->getAttr("parents").asList().begin()).asString() ==
            "look");

    Account acct = smart_dynamic_cast<Account>(objectDefinitions.find("account")->second);
    Account acct_inst;
    acct_inst->setAttr("id", std::string("account_instantiation"));
    assert(acct->getAttr("id").asString() == "account");
    assert(acct_inst->getAttr("id").asString() == "account_instantiation");
    assert(acct->getAttr("parents").asList().size() == 1);
    assert((*acct->getAttr("parents").asList().begin()).asString() ==
            "admin_entity");
    assert(acct_inst->getAttr("parents").asList().size() == 1);
    assert((*acct_inst->getAttr("parents").asList().begin()).asString() ==
            "account");



    {

        Atlas::Objects::Entity::Anonymous anon;
        anon->setLoc("12345");
        ListType velocity;
        velocity.push_back(1.4);
        velocity.push_back(2.4);
        velocity.push_back(3.4);
        anon->setVelocityAsList(velocity);
        ListType bbox;
        bbox.push_back(1.4);
        bbox.push_back(2.4);
        bbox.push_back(3.4);
        bbox.push_back(2.4);
        anon->setAttr("bbox", bbox);

        Atlas::Objects::Operation::Move move;
        move->setFrom("123456");
        move->setTo("123456");
        move->setSeconds(12345678);
        move->setId("123456");
        move->setArgs1(anon);

        Atlas::Objects::Operation::Sight sight;
        sight->setFrom("123456");
        sight->setTo("123456");
        sight->setSeconds(12345678);
        sight->setId("123456");
        sight->setArgs1(move);

        Atlas::Message::MapType map;
        sight->addToMessage(map);
        std::cout << map.size() << std::flush;
        assert(map.size() == 7);
        assert(map["objtype"].String() == "op");
        assert(map["from"].String() == "123456");
        assert(map["to"].String() == "123456");
        assert(map["seconds"].Float() == 12345678);
        assert(map["id"].String() == "123456");
        assert(map["args"].List().size() == 1);


    }

}