Example #1
0
void base_user_module::cmd_conference(std::shared_ptr<user> u, message &msg)
{
    id_number_t gid = msg.header.group;
    auto params = split_params_std(msg.body);
    std::shared_ptr<group> conference;
    try {
        if (params.size() < 2)
        {
            message_composer msgc(warning_message, gid);
            msgc << "Incorrect format! Usage: " << params[0] << " <conference_name> [<participants_names>...]";
            u->deliver_message(msgc());
        } else if (params.size() == 1)
        {
            conference = std::make_shared<conference_room>(get_server(), u->get_name(), u);
            get_server().add_group(conference);
        } else
        {
            std::vector<std::shared_ptr<participant>> pts;
            pts.push_back(u);
            for (auto it = params.begin() + 1; it != params.end(); ++it)
                pts.push_back(get_server().get_participant(*it));

            conference = std::make_shared<conference_room>(get_server(), u->get_name(), std::move(pts));
            get_server().add_group(conference);
        }
    } catch (ptr_nullptr &e) // @todo: change exception to more proper
    {
        message_composer msgc(error_message, gid);
        msgc << "One or more users does not exist!";
        u->deliver_message(msgc());
    } catch (std::logic_error &e)
    {
        Error(get_server().get_logger(), "Logic ERROR in base_user_module::cmd_conference: ", e.what());
    }
}
Example #2
0
bool Island_Compare::operator() (const std::shared_ptr<Island>& i1, const std::shared_ptr<Island>& i2){
  Point p1 = i1->get_location();
  Point p2 = i2->get_location();
  
  //get distance
  double distance1 = cartesian_distance(p1, origin);
  double distance2 = cartesian_distance(p2, origin);
  
  //if distance is the same, compare name
  if(distance1==distance2){
    return i1->get_name()<i2->get_name();
  }
  return distance1<distance2;
}
void ElementModel::add_pad(const std::shared_ptr<PadModel> &pad)
{
	if (get_pad(pad->get_name()))
		return;
	pads.push_back(pad);
	pad->set_parent(shared_from_this());
}
Example #4
0
void base_user_module::cmd_nick(std::shared_ptr<user> u, message &msg)
{
    auto params = split_params_std(msg.body);
    if (params.size() != 2)
    {
        resp_bad_cmd_format_(u, "/nick <new_nick>");
        return;
    }
    std::string newname = params[1], oldname = u->get_name();
    if (oldname == newname)
    {
        message_composer msgc(message_type::warning_message);
        msgc << oldname << " == " << oldname << " --- You kidding, right?! :/";
        u->deliver_message(msgc());
    } else if (get_server().is_username_valid(newname) == false)
    {
        message_composer msgc(message_type::error_message);
        msgc << "Invalid nickname!";
        u->deliver_message(msgc());
    } else if (get_server().change_participant_name(oldname, newname))
    {
        message_composer msgc(message_type::info_message);
        msgc << "User `" << oldname << "` changed nick to `" << newname << "`!";
        get_server().send_to_all(msgc());
    } else
    {
        message_composer msgc(message_type::error_message);
        msgc << "Nick which you choose (" << newname << ") is in use. Try another one!";
        u->deliver_message(msgc());
    }
}
static void set_omp_params(std::shared_ptr<apex_tuning_request> request) {
	//std::cout << __func__ << std::endl;
        std::shared_ptr<apex_param_enum> thread_param = std::static_pointer_cast<apex_param_enum>(request->get_param("omp_num_threads"));
        const int num_threads = atoi(thread_param->get_value().c_str());

        std::shared_ptr<apex_param_enum> schedule_param = std::static_pointer_cast<apex_param_enum>(request->get_param("omp_schedule"));
        const std::string schedule_value = schedule_param->get_value();
        omp_sched_t schedule = omp_sched_auto;
        if(schedule_value == "static") {
            schedule = omp_sched_static;
        } else if(schedule_value == "dynamic") {
            schedule = omp_sched_dynamic;
        } else if(schedule_value == "guided") {
            schedule = omp_sched_guided;
        } else if(schedule_value == "auto") {
            schedule = omp_sched_auto;
        } else {
            throw std::invalid_argument("omp_schedule");
        }

        std::shared_ptr<apex_param_enum> chunk_param = std::static_pointer_cast<apex_param_enum>(request->get_param("omp_chunk_size"));
        const int chunk_size = atoi(chunk_param->get_value().c_str());

        const char * name = request->get_name().c_str();

        if(apex_openmp_policy_verbose) {
            fprintf(stderr, "name: %s, num_threads: %d, schedule %d, chunk_size %d\n", name, num_threads, schedule, chunk_size);
        }

        omp_set_num_threads(num_threads);
        omp_set_schedule(schedule, chunk_size);
}
Example #6
0
bool Container::insert(const std::shared_ptr<Item> & item)
{
	// any stackable type passed in will only increment the type's count by one

	if (item == nullptr) return false; // well, something went wrong

	if (U::is<Stackable>(item) && this->contains(item->get_name())) // if the item is stackable and already exists in the container
	{
		// increment the existing item in the container
		U::convert_to<Stackable>(contents.find(item->get_name())->second)->amount++;
	}
	else // the item is either not stackable, or is not in the container
	{
		contents.insert(make_pair(item->get_name(), item));
	}

	return true;
}
bool odata_json_writer::is_type_serializable(const std::shared_ptr<edm_named_type>& property_type)
{
    if (property_type)
    {
        if (property_type->get_type_kind() == edm_type_kind_t::Collection
                || property_type->get_type_kind() == edm_type_kind_t::Entity
                || property_type->get_type_kind() == edm_type_kind_t::Complex
                || property_type->get_type_kind() == edm_type_kind_t::Primitive
                || property_type->get_type_kind() == edm_type_kind_t::Enum
                || (property_type->get_type_kind() == edm_type_kind_t::PayloadAnnotation)
                && (property_type->get_name() == PAYLOAD_ANNOTATION_TYPE || property_type->get_name() == PAYLOAD_ANNOTATION_ID))
        {
            return true;
        }
    }

    return false;
}
void odata_json_operation_payload_parameter_writer::handle_serialize_odata_parameter(
	::utility::stringstream_t& ss, const std::shared_ptr<::odata::core::odata_parameter>& parameter, ::utility::char_t mark, ::utility::char_t separator)
{
	if (parameter && parameter->get_value() && !parameter->get_name().empty())
	{
		if (mark)
		{
			ss << mark << parameter->get_name() << mark;
		}
		else
		{
			ss << parameter->get_name();
		}

		ss << separator;

		handle_serialize_odata_value(ss, parameter->get_value()->get_value_type(), parameter->get_value());
	}
}
void UberShaderFactory::load_main_functions(std::shared_ptr<ShadingModel> const& model) {


    // write main() method <model>_main(<uniforms>) ----------------------------
    std::stringstream stream;
    stream << "void " << model->get_name() << "_main(";

    auto uniform(model->get_stages()[stage_].get_uniforms().begin());

    while (uniform != model->get_stages()[stage_].get_uniforms().end()) {
        stream << enums::uniform_type_to_string(uniform->second) << " "
               << uniform->first;

        if (++uniform != model->get_stages()[stage_].get_uniforms().end())
            stream << ", ";
    }

    std::string body(model->get_stages()[stage_].get_body());

    stream << ") {" << std::endl;

    // add output variables to the beginning of the main method ----------------
    for (auto const& output : model->get_stages()[stage_].get_outputs()) {
        stream << "    " << enums::output_type_to_string(output.second) << " "
               << output.first << " = " << enums::output_type_to_string(output.second) << "(0);" << std::endl;
    }

    // write body --------------------------------------------------------------
    stream << body << std::endl;

    // write output variables to gua_out_layer_* at end of the main method -----
    for (auto const& output : model->get_stages()[stage_].get_outputs()) {
        stream << "    " << output_mapping_.get_output_string(
                                model->get_name(), output.first) << " = "
               << output.first << ";" << std::endl;
    }

    stream << "}" << std::endl;

    main_functions_[model->get_name()] = stream.str();
}
Example #10
0
// bloomeries
std::string Room::add_item_to_bloomery(const std::shared_ptr<Forgeable> & item)
{
	// save an iterator
	auto bloomery_it = contents.find(C::BLOOMERY_ID);

	if (bloomery_it == contents.cend())
	{
		return "There is no bloomery here.";
	}

	if (U::is_not<Forgeable>(item))
	{
		return "You cannot put a " + item->get_name() + " in a bloomery.";
	}

	// save a new shared_ptr to the bloomery in question
	std::shared_ptr<Bloomery> bloomery = U::convert_to<Bloomery>(bloomery_it->second);

	bloomery->add_to_bloomery(item);

	return "You place the " + item->get_name() + " in a bloomery.";
}
Example #11
0
void Amusement::push(std::shared_ptr<Person> per, time_unit distance_time, std::shared_ptr<Amusement> amu){

    //_log_mutex.lock();
    //std::time_t beg = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
    //std::cout << std::this_thread::get_id() << " Amusement " << amu->get_name() << " begin push ";
    //std::cout << std::setw(8) << std::setfill('0') << per->get_logid();
    //std::cout << " time:" << std::put_time(std::localtime(&beg), "%F %T") << '\n';
    //_log_mutex.unlock();

    std::this_thread::sleep_for(distance_time);

    //_log_mutex.lock();
    //std::time_t end = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
    //std::cout << std::this_thread::get_id() << " Amusement " << amu->get_name() << " end push ";
    //std::cout << std::setw(8) << std::setfill('0') << per->get_logid();
    //std::cout << " time:" << std::put_time(std::localtime(&end), "%F %T") << '\n';
    //_log_mutex.unlock();

    per->insert_played(amu->get_name());
    //_log_mutex.lock();
    //per->print_played_amu();
    //_log_mutex.unlock();

    if(per->get_play_count() > 6)
    {
        per->delete_played("in_out");
    }


    amu->get_ranks_mutex().lock();
    amu->get_ranks().push_back(std::shared_ptr<Person>(per));
    amu->get_ranks_mutex().unlock();
    _log_mutex.lock();
    std::cout << std::setw(8) << std::setfill('0') <<  per->get_logid();
    std::cout << " has arraive " << amu->get_name() << " Amusement ." << std::endl;
    _log_mutex.unlock();

}
void AudioSinksManager::unregister_audio_sink(std::shared_ptr<InternalAudioSink> sink) {
    logger->trace("(AudioSinkManager) Unregistering audio_sink '{}'", sink->get_name());

    uint32_t sink_idx = sink->get_sink_idx();
    if (sink_idx != static_cast<uint32_t>(-1)) {
        sink_idx_audio_sink.erase(sink_idx);
    }

    sink_identifier_audio_sink.erase(sink->get_identifier());
    audio_sinks.erase(sink);
    if (audio_sinks.empty() && stopping) {
        if (context) {
            logger->trace("(AudioSinkManager) Disconnect context");
            pa_context_disconnect(context);
        }
    }
}
Example #13
0
    void on_edit_encounter()
    {
        auto selected_encounter = encounters_page_->get_selected_encounter();

        if (selected_encounter)
        {
            current_encounter_ = selected_encounter;
            encounter_editor_->set_encounter_name(
                current_encounter_->get_name());
            encounter_editor_->set_encounter_beasts(
                current_encounter_->get_beasts());
            encounter_editor_->set_bestiary(
                bestiary_page_->get_beasts());

            encounter_tab_card_->select_face(encounter_editor_face);
            encounter_tab_card_->set_focus();
        }
    }
odata::utility::json::value odata_json_writer::serialize(std::shared_ptr<odata_service_document_element> service_document_element)
{
    odata::utility::json::value result = odata::utility::json::value::object();
    result[JSON_NAME] = odata::utility::json::value::string(service_document_element->get_name());

    ::odata::utility::string_t kind;
    switch(service_document_element->get_kind())
    {
    case ENTITY_SET:
        kind = JSON_ENTITYSET
               break;
    case SINGLETON:
        kind = JSON_SINGLETON
               break;
    case FUNCTION_IMPORT:
        kind = JSON_FUNCTIONIMPORT
               break;
    }
    result[JSON_KIND] = odata::utility::json::value::string(kind);
    result[JSON_URI] = odata::utility::json::value::string(service_document_element->get_url());

    return result;
}
Example #15
0
SurfaceUI::SurfaceUI( const std::shared_ptr< flat::Surface >& surface )
: UI( get_builder_filename(), "surface_model_widget" ), m_surface( surface )
{ 
  std::clog << "flat::SurfaceUI::SurfaceUI" << std::endl; 

  Gtk::Label*	surface_name_label;
  get_builder()->get_widget( "surface_name_label", surface_name_label ); 
  surface_name_label->set_text( surface->get_name() );

  Gtk::CheckButton* curvature_update_check;
  get_builder()->get_widget( "curvature_update_check", curvature_update_check );
  curvature_update_check->signal_clicked().connect( sigc::mem_fun( *this, &SurfaceUI::toggle_curvature_update ) );
  m_curvature_update = curvature_update_check->get_active();

  Gtk::Label*	num_vertices_label;
  get_builder()->get_widget( "num_vertices_value_label", num_vertices_label );
  num_vertices_label->set_text( boost::lexical_cast<std::string>( surface->num_vertices() ) );
  
  get_builder()->get_widget( "height_value_label", m_height_label );

  get_builder()->get_widget( "curvature_value_label", m_curvature_label );
  
  update();
}
Example #16
0
Update_Messages Room::damage_door(const std::string & surface_ID, const std::shared_ptr<Item> & equipped_item, const std::string & username)
{
	// test if the surface is valid
	if (!U::contains(C::surface_ids, surface_ID))
	{
		return Update_Messages(surface_ID + " is not a valid surface.");
	}

	// test if this room has the surface
	if (!this->has_surface(surface_ID))
	{
		if (surface_ID == C::CEILING || surface_ID == C::FLOOR)
		{
			return Update_Messages("There is no " + surface_ID + ".");
		}
		else
		{
			return Update_Messages("There is no " + surface_ID + " wall here.");
		}
	}

	// test if the surface has the door
	if (!this->room_sides.find(surface_ID)->second.has_door())
	{
		return Update_Messages("There is no door here.");
	}

	// extract the ID of the attacking implement (ATTACK_COMMAND for bare-hands melee attack)
	const std::string equipped_item_id = ((equipped_item != nullptr) ? equipped_item->get_name() : C::ATTACK_COMMAND);

	// check if the player's equipped weapon exists in the damage table
	if (C::damage_tables.find(equipped_item_id) == C::damage_tables.cend())
	{
		return Update_Messages("Error occured: Damage lookup tables contain no info to attack using " + equipped_item_id + ".");
	}

	// the damage map for this implement exists, copy it here
	const std::map<std::string, int> item_damage_table = C::damage_tables.find(equipped_item_id)->second;

	// a wall exists; check if the wall does not have an intact door
	if (!this->room_sides.find(surface_ID)->second.has_intact_door())
	{
		return Update_Messages("There is only a pile of rubble where a door once was.");
	}

	// a door exists AND it is intact

	// copy the material of the door
	const std::string door_material_ID = this->room_sides.find(surface_ID)->second.get_door()->get_material_ID();

	// check if the material of the door being attacked exists in the damage table for the attacking implement
	if (item_damage_table.find(door_material_ID) == item_damage_table.cend())
	{
		// ... contains no info to use staff to damage stone."
		return Update_Messages("Error occured: Damage lookup tables contain no info to use "
			+ equipped_item_id + " to damage "
			+ door_material_ID + " door.");
	}

	// door and damage table entry exist, inflict damage*-1
	{
		std::stringstream ss;
		ss << "door health before attack: " << room_sides.find(surface_ID)->second.get_door()->get_health() << std::endl; // debugging
		std::cout << ss.str();
	}
	room_sides.find(surface_ID)->second.get_door()->update_health_by(item_damage_table.find(door_material_ID)->second * -1);
	{
		std::stringstream ss;
		ss << "door health after attack:  " << room_sides.find(surface_ID)->second.get_door()->get_health() << std::endl; // debugging
		std::cout << ss.str();
	}

	// if the door has 0 health
	if (room_sides.find(surface_ID)->second.get_door()->is_rubble())
	{
		// the door collapses
		return Update_Messages("The door breaks and collapses.", username + " breaks the door.", true);
	}
	else
	{
		// the door holds
		return Update_Messages("You damage the " + surface_ID + " door using your " +
			((equipped_item_id == C::ATTACK_COMMAND) ? "bare hands." : (equipped_item_id + ".")),

			// Bob damages the west door with
			username + " damages the " + surface_ID + " door with " +
			((equipped_item_id == C::ATTACK_COMMAND)
				// bare hands. / an axe.
				? "bare hands." : U::get_article_for(equipped_item_id) + " " + equipped_item_id + "."),

			true);
	}
}
Example #17
0
// damage surface
Update_Messages Room::damage_surface(const std::string & surface_ID, const std::shared_ptr<Item> & equipped_item, const std::string & username)
{
	// test if the surface is valid
	if (!U::contains(C::surface_ids, surface_ID))
	{
		return Update_Messages(surface_ID + " is not a valid surface.");
	}

	// test if this room has the surface
	if (!this->has_surface(surface_ID))
	{
		if (surface_ID == C::CEILING || surface_ID == C::FLOOR)
		{
			return Update_Messages("There is no " + surface_ID + ".");
		}
		else
		{
			return Update_Messages("There is no " + surface_ID + " wall here.");
		}
	}

	// the surface exists, test if the surface is rubble
	if (room_sides.find(surface_ID)->second.is_rubble())
	{
		return Update_Messages("There is only rubble where a wall once was.");
	}

	// extract the ID of the attacking implement (ATTACK_COMMAND for bare-hands melee attack)
	const std::string equipped_item_id = ((equipped_item != nullptr) ? equipped_item->get_name() : C::ATTACK_COMMAND);

	// check if the player's equipped weapon exists in the damage table
	if (C::damage_tables.find(equipped_item_id) == C::damage_tables.cend())
	{
		return Update_Messages("Error occured: Damage lookup tables contain no info to attack using " + equipped_item_id + ".");
	}

	// the damage map for this implement exists, copy it here
	const std::map<std::string, int> item_damage_table = C::damage_tables.find(equipped_item_id)->second;

	// copy the surface's material_ID
	const std::string surface_material_ID = this->room_sides.find(surface_ID)->second.get_material_id();

	// check if the material of the wall being attacked exists in the damage table for the implement
	if (item_damage_table.find(surface_material_ID) == item_damage_table.cend())
	{
		// ... contains no info to use staff to damage stone."
		return Update_Messages("Error occured: Damage lookup tables contain no info to use "
			+ equipped_item_id + " to damage "
			+ surface_material_ID + " wall.");
	}

	// surface exists, inflict damage*-1
	{
		std::stringstream ss;
		ss << "surface health before attack: " << room_sides.find(surface_ID)->second.get_health() << std::endl;
		std::cout << ss.str();
	}
	room_sides.find(surface_ID)->second.change_health(item_damage_table.find(surface_material_ID)->second*-1);
	{
		std::stringstream ss;
		ss << "surface health after attack:  " << room_sides.find(surface_ID)->second.get_health() << std::endl;
		std::cout << ss.str();
	}

	// after applying damage, test again to see if the surface is rubble
	if (room_sides.find(surface_ID)->second.is_intact())
	{
		// the surface holds

		return Update_Messages("You damage the " + // You damage the
			// ceiling / wall to your west
			((surface_ID == C::CEILING || surface_ID == C::FLOOR) ? surface_ID : "wall to your " + surface_ID)
			// using your sword. / using your bare hands.
			+ " using your " +
			((equipped_item_id == C::ATTACK_COMMAND) ? "bare hands." : (equipped_item_id + ".")),

			// Bob uses
			username + " uses " +
			((equipped_item_id == C::ATTACK_COMMAND)
				// bare hands / an axe
				? "bare hands" : U::get_article_for(equipped_item_id) + " " + equipped_item_id) +
			// to damage the
			" to damage the " +
			// ceiling. / wall to your west.
			((surface_ID == C::CEILING || surface_ID == C::FLOOR) ? surface_ID : "wall to your " + surface_ID) + ".");
	}

	// the surface collapses

	// ensure the surface no longer has a door
	room_sides.find(surface_ID)->second.remove_door();

	// if the collapsing surface is a ceiling
	if (surface_ID == C::CEILING)
	{
		// remove the ceiling object completely
		room_sides.erase(surface_ID);

		// add a debris object to the room
		this->insert(Craft::make(C::DEBRIS_ID));
	}

	return Update_Messages(
		(surface_ID == C::CEILING || surface_ID == C::FLOOR)
		? "The " + surface_ID + " collapses."
		: "The wall collapses.",

		// Bob collapses the
		username + " collapses the " +
		((surface_ID == C::CEILING || surface_ID == C::FLOOR)
			// ceiling/floor
			? surface_ID + "."
			// wall to your west
			: "wall to your " + surface_ID + "."),
		true);
}
    CHECK(tile2.ParseFromString(buffer));
    CHECK(1 == tile2.layers_size());
    vector_tile::Tile_Layer const& layer2 = tile2.layers(0);
    CHECK(std::string("layer") == layer2.name());
    CHECK(1 == layer2.features_size());

    mapnik::layer lyr2("layer",map.srs());

    protozero::pbf_reader pbf_tile(buffer);
    pbf_tile.next();
    protozero::pbf_reader layer3 = pbf_tile.get_message();

    std::shared_ptr<mapnik::vector_tile_impl::tile_datasource_pbf> ds = std::make_shared<
                                    mapnik::vector_tile_impl::tile_datasource_pbf>(
                                        layer3,0,0,0);
    CHECK(ds->get_name() == "layer");
    mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789);
    ds->set_envelope(bbox);
    CHECK( ds->type() == mapnik::datasource::Vector );
    CHECK( ds->get_geometry_type() == mapnik::datasource_geometry_t::Collection );
    mapnik::layer_descriptor lay_desc = ds->get_descriptor();
    std::set<std::string> expected_names;
    expected_names.insert("bool");
    expected_names.insert("boolf");
    expected_names.insert("double");
    expected_names.insert("float");
    expected_names.insert("int");
    expected_names.insert("name");
    expected_names.insert("uint");
    std::size_t desc_count = 0;
    for (auto const& desc : lay_desc.get_descriptors())
void MaterialShaderDatabase::add(std::shared_ptr<MaterialShader> const& material) {
  Database<MaterialShader>::add(material->get_name(), material);
}
Example #20
0
  void
  Vcd_instrumenter::write_signal_list(std::ostream& os,
      std::shared_ptr<Module_inspector> insp) {
    auto mod = insp->module();
    os << "$scope module "
      << mod->name
      << " $end\n";

    for(std::size_t i=0; i<insp->num_elements(); ++i) {
      auto obj = insp->get_object(i);
      // Don't include pointers to instantiated modules
      if( mod->instantiations.count(obj->name) != 0 )
        continue;

      if( obj->type == ir::Builtins<sim::Llvm_impl>::types["float"] ) {
        os << "$var "
          << "real 1 "
          << reference(m_ref_counter++)
          << ' '
          << insp->get_name(i)
          << " $end\n";
      } else if( !obj->type->elements.empty() ) {
        auto bits = insp->get_element_bits(i);
        std::size_t j = 0;
        for(auto const& elem : obj->type->elements) {
          if( elem.second->type == ir::Builtins<sim::Llvm_impl>::types["float"] )
            os << "$var "
              << "real 1 "
              << reference(m_ref_counter++)
              << ' '
              << insp->get_name(i)
              << '.'
              << elem.first
              << " $end\n";
          else
            os << "$var "
              << "integer "
              << bits[j].size()
              << ' '
              << reference(m_ref_counter++)
              << ' '
              << insp->get_name(i)
              << '.'
              << elem.first
              << " $end\n";
          ++j;
        }
      } else {
        auto bits = insp->get_bits(i);

        if( bits.size() > 0 ) {
          os << "$var "
            << "integer "
            << bits.size()
            << ' '
            << reference(m_ref_counter++)
            << ' '
            << insp->get_name(i)
            << " $end\n";
        }
      }
    }
  }
std::shared_ptr<dwarf::spec::basic_die> 
process_image::discover_heap_object(addr_t heap_loc,
    std::shared_ptr<dwarf::spec::type_die> imprecise_static_type,
    addr_t *out_object_start_addr)
{
    static bool warned = false;
	using std::shared_ptr;
	using dwarf::lib::Dwarf_Unsigned;
	using dwarf::lib::Dwarf_Off;
    
    assert (alloc_list_head_ptr_addr != 0);

    void *alloc_list_head_addr = *unw_read_ptr<void*>(
        unw_as, unw_priv, reinterpret_cast<void**>(alloc_list_head_ptr_addr));
    // if my template class works, we should just be able to walk the list...
	unw_read_ptr<alloc> n(unw_as, 
        			unw_priv,
        			reinterpret_cast<alloc*>(alloc_list_head_addr));
    std::cerr << "Remote read head alloc is at " << alloc_list_head_addr 
        << " and has begin " << n->begin
        << ", size " << static_cast<unsigned>(n->size) /* avoid size_t printing in hex */
        << " bytes, next " << n->next
        << std::endl;    
	
	// FIXME: if n has precise static type info in it,
	// just retrieve it and we're done.
	
	for (;
            	n != 0;
                n = n->next)
    {
        off_t offset_into_block = reinterpret_cast<char*>(heap_loc) 
            - reinterpret_cast<char*>(n->begin);
        // candidates are containing types which satisfy our offset constraints
        std::vector<shared_ptr<spec::type_die> > candidates;
    	if (heap_loc >= reinterpret_cast<addr_t>(n->begin) 
			&& offset_into_block < n->size)
        {
        	std::cerr << "Detected that heap location 0x" << std::hex << heap_loc
            	<< " is part of region beginning 0x" << std::hex << n->begin
                << " with size " << n->size << " bytes." << std::endl;

            /* Now we do what's described in the Cake paper. 
             * 
             * First, consider block-scale adjustments. 
             * In this, the pointer is
             * - to a block whose size is a multiple of the expected size;
             * - into the block at an integer multiple of the element size. */

            auto type = imprecise_static_type;
            boost::optional<Dwarf_Unsigned> opt_byte_size = 
                type->calculate_byte_size();
            assert (opt_byte_size);
            Dwarf_Unsigned byte_size = *opt_byte_size;
            //	= dwarf::abstract::Die_abstract_is_type<dwarf::encap::die>
            //    	::calculate_byte_size(*type);
            if (n->size % byte_size == 0
                && offset_into_block % byte_size == 0)
            {
                std::cerr << "Detected array of " 
                    // workaround size_t hex printing annoyance
                    << static_cast<unsigned long>(n->size / byte_size)
                    << " elements of type " << 
						(imprecise_static_type->get_name() ? *imprecise_static_type->get_name() : "(anon)" )
                    << " (size " << static_cast<unsigned long>(n->size) << ")"
                    << std::endl;
            } // end if block-scale
            else
            {
                /* The tricky one: byte-scale adjustment.
                 * Find all the admissible containing types
                 * whose byte-size matches the block size. */
				
				/* Q: For DwarfPython, what are we going to do when we
				 * have no imprecise static type? 
				 * A: Make sure DwarfPython-allocated objects store
				 * precise static type info at allocation time, or
				 * (for strings that are embedded in the AST) some
				 * time before we try to do the discovery thing on them. */
				assert(imprecise_static_type);
				std::vector<std::shared_ptr<dwarf::spec::type_die> > candidates;

				/* We need the reachability in the master containment
				 * relation, because we want to handle indirect containment.
				 * So we want to find all the types reachable from the
				 * (reflexive) containment relation. We have the non-reflexive
				 * relation, so we just add back in the starting node. */
                auto containing_types = 
					master_type_containment.equal_range(
						imprecise_static_type->get_concrete_type()->opt_ident_path_from_cu()
					);
				for (auto i_containment_pair = containing_types.first;
						i_containment_pair != containing_types.second;
						++i_containment_pair)
				{
					// FIXME: use reachability here!
					assert(master_type_equivalence[i_containment_pair->second].begin()
						!= master_type_equivalence[i_containment_pair->second].end());
						
					auto containing_type_position = // look up an arbitrary element of the equiv. class
						*master_type_equivalence[i_containment_pair->second].begin();
					
					auto containing_type = boost::dynamic_pointer_cast<dwarf::spec::type_die>(
						(*containing_type_position.p_ds)[containing_type_position.off]);
					assert(containing_type);
					
					// Now for each position at which this type contains our imprecise type
					for (auto i_child = containing_type->children_begin();
							i_child != containing_type->children_end();
							++i_child)
					{
                    	if ((*i_child)->get_tag() == DW_TAG_member
                        	|| (*i_child)->get_tag() == DW_TAG_inheritance)
                    	{
							// skip occurrences where this doesn't have the type we're interested in
							auto child_describing_layout
							 = boost::dynamic_pointer_cast<dwarf::spec::with_type_describing_layout_die>(
							 	*i_child);
							if (!child_describing_layout
							 || !child_describing_layout->get_type()
							 || !(*child_describing_layout->get_type())->get_concrete_type()
							 || (*child_describing_layout->get_type())->get_concrete_type()->
							 	opt_ident_path_from_cu()
							 	!= imprecise_static_type->get_concrete_type()->opt_ident_path_from_cu()) 
								continue;
							// FIXME: use more abstract test here
							// (Define a function that gets the equivalence class identifier
						
                        	assert(containing_type->calculate_byte_size());
							
							

                        	if (*containing_type->calculate_byte_size() == n->size)
                        	{
                            	// check the offset as well
                            	switch((*i_child)->get_tag())
                            	{
                                	case DW_TAG_member: {
                                    	auto member = boost::dynamic_pointer_cast<spec::member_die>(
                                        		*i_child);
							        	Dwarf_Off containing_offset = dwarf::lib::evaluator(
                                        	member->get_data_member_location()->at(0), 
                                    	   (*i_child)->get_spec(),
                                    	   std::stack<Dwarf_Unsigned>(
                               	        	std::deque<Dwarf_Unsigned>(1, 0UL))).tos();
                                    	if (containing_offset == 0)
                                    	{
                            	        	// success -- this is admissible
                                        	candidates.push_back(containing_type);
                                    	}
                                	} break;
                                	case DW_TAG_inheritance: {
                                    	auto inheritance = boost::dynamic_pointer_cast<
                                        	spec::inheritance_die>(*i_child);
							        	Dwarf_Off containing_offset = dwarf::lib::evaluator(
			 	                        	inheritance->get_data_member_location()->at(0), 
                                    	   (*i_child)->get_spec(),
                                    	   std::stack<Dwarf_Unsigned>(
                               	        	std::deque<Dwarf_Unsigned>(1, 0UL))).tos();                   
                        	        	if (containing_offset == offset_into_block)
                                    	{
	                                    	candidates.push_back(containing_type);
                                    	}
                                	} break;
                                	default: assert(false); break;
                            	} // end switch
                        	} // end if byte_size
                    	} // end if tag
					} // end for child
                } // end for backref

                switch (candidates.size())
                {
					case 0: goto did_not_understand;
                    case 1: // the good case
		                std::cerr << "Sucessfully resolved pointer at 0x";
        		            std::cerr << std::hex << heap_loc;
                	        std::cerr << " to type ";
                            std::cerr << *candidates.at(0);
                            std::cerr << std::endl;
                        return candidates.at(0);
                    default: // the ambiguous case
		                std::cerr << "Warning: could not unambiguously resolve pointer 0x"
        		            << std::hex << heap_loc
                	        << ". Candidate types are: ";
                        for (auto j = candidates.begin(); j != candidates.end(); j++)
                        {
                            std::cerr << **j << std::endl;
                        }
                        break;
				} // end switch         
                break; // exit for-each-block loop
                did_not_understand:
                	std::cerr << "Warning: did not understand pointer 0x"
                    	<< std::hex << heap_loc
                        << " into heap region beginning 0x" << std::hex << n->begin
	                    << " with size " << n->size << " bytes." << std::endl;
                break;
            } // end else look for byte-scale 
        } // end if block matched
	} // end for each block
}
Example #22
0
void GroupsManager::add_group(const std::shared_ptr<Group>& group) {
    groups.insert({group->get_name(), group});
    //relations.insert({group->get_name(), });
}
Example #23
0
void on_component_removed(std::shared_ptr<IComponent<>> component) {
	std::cout << "Component " << component->get_name() << " was removed from " << component->get_owner()->get_name() << "!" << std::endl;
}
Example #24
0
void on_component_added(std::shared_ptr<IComponent<>> component) {
	std::cout << "Component " << component->get_name() << " was added to " << component->get_owner()->get_name() << "!" << std::endl;
}
Example #25
0
void Graph::add_node(std::shared_ptr<Node> node) {
    node_pool.insert(std::make_pair(node->get_name(), node));
    out_edges[node] = std::list<std::shared_ptr<const Node> > {};
    in_edges[node] = std::list<std::shared_ptr<const Node> > {};
    basal_nodes.insert(node_pool.at(node->get_name()));
}
Example #26
0
void present_winner(std::shared_ptr<Player> player){
//  std::cout << player->get_name() << std::endl;
  player->get_name();
}
Example #27
0
void Renderable::add_uniform_listener(const std::shared_ptr<IProperty> &prop)
{
	for (const auto &map_entry : material->get_render_pass_configs())
	{
		const std::string &render_pass_name = map_entry.first;
		const Material::RenderPassConfig &settings = map_entry.second;

		const std::vector<std::string> &unused_uniforms = settings.unused_uniforms;

		if (std::find(unused_uniforms.begin(), unused_uniforms.end(), prop->get_name()) == unused_uniforms.end())
		{
			continue;
		}

		const Core::ShaderPtr &shader = settings.shader;
		const Core::ShaderVariableInfo info = shader->get_uniform_info(prop->get_name());

		switch (info.type)
		{
		case GL_BOOL:
			{
				add_uniform<bool>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_BYTE:
			{
				add_uniform<char>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_UNSIGNED_BYTE:
			{
				add_uniform<unsigned char>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_SHORT:
			{
				add_uniform<short>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_UNSIGNED_SHORT:
			{
				add_uniform<unsigned short>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_INT:
			{
				add_uniform<int>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_UNSIGNED_INT:
			{
				add_uniform<unsigned int>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT:
			{
				add_uniform<float>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT_VEC2:
			{
				add_uniform<glm::vec2>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_INT_VEC2:
			{
				add_uniform<glm::ivec2>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_UNSIGNED_INT_VEC2:
			{
				add_uniform<glm::uvec2>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT_VEC3:
			{
				add_uniform<glm::vec3>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_INT_VEC3:
			{
				add_uniform<glm::ivec3>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_UNSIGNED_INT_VEC3:
			{
				add_uniform<glm::uvec3>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT_VEC4:
			{
				add_uniform<glm::vec4>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_INT_VEC4:
			{
				add_uniform<glm::ivec4>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_UNSIGNED_INT_VEC4:
			{
				add_uniform<glm::uvec4>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT_MAT2:
			{
				add_uniform<glm::mat2>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT_MAT3:
			{
				add_uniform<glm::mat3>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_FLOAT_MAT4:
			{
				add_uniform<glm::mat4>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		case GL_SAMPLER_2D:
		case GL_SAMPLER_CUBE:
			{
				// FIXME: get texture units somehow
				add_uniform<Core::TexturePtr>(render_pass_name, prop, shader->get_handle(), info.location);
				break;
			}

		default:
			{
				clan::StringFormat message("Uknown/unhandled type (%1) for uniform (%2) with length (%3)");
				message.set_arg(1, info.type);
				message.set_arg(2, info.name);
				message.set_arg(3, info.size);

				std::cerr << message.get_result();
				break;
			}
		}
	}
}