#include <simgrid/forward.h>
#include <xbt/dynar.h>
+#include <memory>
+#include <string>
#include <unordered_map>
#include <vector>
-#include <string>
namespace simgrid {
namespace jedule{
class XBT_PUBLIC Container {
public:
explicit Container(const std::string& name);
- ~Container();
+ Container(const Container&) = delete;
+ Container& operator=(const Container&) = delete;
private:
int last_id_;
std::string name;
std::unordered_map<const char*, unsigned int> name2id;
Container *parent = nullptr;
- std::vector<Container*> children;
+ std::vector<std::unique_ptr<Container>> children;
std::vector<sg_host_t> resource_list;
void add_child(Container* child);
void add_resources(std::vector<sg_host_t> hosts);
THROWF(tracing_error, 0, "can't create a new type with no name or alias");
if (father != nullptr){
- father->children_.insert({alias, this});
+ father->children_.emplace(alias, this);
XBT_DEBUG("new type %s, child of %s", get_cname(), father->get_cname());
}
if (trace_format == simgrid::instr::TraceFormat::Paje) {
}
}
-Type::~Type()
-{
- for (auto elm : children_)
- delete elm.second;
-}
-
ContainerType::ContainerType(const std::string& name, Type* father) : Type(name, name, "", father)
{
XBT_DEBUG("ContainerType %s(%lld), child of %s(%lld)", get_cname(), get_id(), father->get_cname(), father->get_id());
Type* Type::by_name(const std::string& name)
{
Type* ret = nullptr;
- for (auto elm : children_) {
+ for (auto const& elm : children_) {
if (elm.second->name_ == name) {
if (ret != nullptr) {
THROWF (tracing_error, 0, "there are two children types with the same name?");
} else {
- ret = elm.second;
+ ret = elm.second.get();
}
}
}
{
auto cont = children_.find(name);
std::string mycolor = color.empty() ? "1 1 1" : color;
- return cont == children_.end() ? new VariableType(name, mycolor, this) : static_cast<VariableType*>(cont->second);
+ return cont == children_.end() ? new VariableType(name, mycolor, this)
+ : static_cast<VariableType*>(cont->second.get());
}
LinkType* Type::by_name_or_create(const std::string& name, Type* source, Type* dest)
ret->log_definition(source, dest);
return ret;
} else
- return static_cast<LinkType*>(it->second);
+ return static_cast<LinkType*>(it->second.get());
}
}
}
#define INSTR_PAJE_TYPES_HPP
#include "src/instr/instr_private.hpp"
+#include <memory>
#include <sstream>
#include <string>
#include <vector>
Type* father_;
public:
- std::map<std::string, Type*> children_;
+ std::map<std::string, std::unique_ptr<Type>> children_;
Container* issuer_ = nullptr;
std::stringstream stream_;
Type(const std::string& name, const std::string& alias, const std::string& color, Type* father);
- virtual ~Type();
+ virtual ~Type() = default;
const std::string& get_name() const { return name_; }
const char* get_cname() { return name_.c_str(); }
template <class T> T* by_name_or_create(const std::string& name)
{
auto cont = children_.find(name);
- return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second);
+ return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
}
void set_calling_container(Container* container) { issuer_ = container; }
if (root->get_name() == "LINK")
root->by_name_or_create(std::string("b") + new_typename, color);
- for (auto elm : root->children_) {
- recursiveNewVariableType(new_typename, color, elm.second);
+ for (auto const& elm : root->children_) {
+ recursiveNewVariableType(new_typename, color, elm.second.get());
}
}
if (root->get_name() == father_type) {
root->by_name_or_create(new_typename, color);
}
- for (auto elm : root->children_)
- recursiveNewUserVariableType(father_type, new_typename, color, elm.second);
+ for (auto const& elm : root->children_)
+ recursiveNewUserVariableType(father_type, new_typename, color, elm.second.get());
}
void instr_new_user_variable_type(const std::string& father_type, const std::string& new_typename,
if (root->get_name() == father_type)
root->by_name_or_create<simgrid::instr::StateType>(new_typename);
- for (auto elm : root->children_)
- recursiveNewUserStateType(father_type, new_typename, elm.second);
+ for (auto const& elm : root->children_)
+ recursiveNewUserStateType(father_type, new_typename, elm.second.get());
}
void instr_new_user_state_type(const std::string& father_type, const std::string& new_typename)
if (root->get_name() == type_name)
static_cast<simgrid::instr::StateType*>(root)->add_entity_value(val, color);
- for (auto elm : root->children_)
- recursiveNewValueForUserStateType(type_name, val, color, elm.second);
+ for (auto const& elm : root->children_)
+ recursiveNewValueForUserStateType(type_name, val, color, elm.second.get());
}
void instr_new_value_for_user_state_type(const std::string& type_name, const char* value, const std::string& color)
container_name2container.insert({this->name, this});
}
-Container::~Container()
-{
- for (auto const& child : this->children)
- delete child;
-}
-
void Container::add_child(jed_container_t child)
{
xbt_assert(child != nullptr);
- this->children.push_back(child);
+ this->children.emplace_back(child);
child->parent = this;
}
int child_nb = -1;
for (auto const& child : this->parent->children) {
- if( child == this) {
+ if (child.get() == this) {
child_nb = i;
break;
}
integral_.push_back(integral);
}
-CpuTiTmgr::~CpuTiTmgr()
-{
- delete profile_;
-}
-
/**
* @brief Integrate trace
*
CpuTiTmgr::CpuTiTmgr(kernel::profile::Profile* speed_profile, double value) : speed_profile_(speed_profile)
{
double total_time = 0.0;
- profile_ = 0;
+ profile_.reset(nullptr);
/* no availability file, fixed trace */
if (not speed_profile) {
for (auto const& val : speed_profile->event_list)
total_time += val.date_;
- profile_ = new CpuTiProfile(speed_profile);
+ profile_.reset(new CpuTiProfile(speed_profile));
last_time_ = total_time;
total_ = profile_->integrate_simple(0, total_time);
#include "src/surf/cpu_interface.hpp"
#include <boost/intrusive/list.hpp>
+#include <memory>
namespace simgrid {
namespace kernel {
CpuTiTmgr(profile::Profile* speed_profile, double value);
CpuTiTmgr(const CpuTiTmgr&) = delete;
CpuTiTmgr& operator=(const CpuTiTmgr&) = delete;
- ~CpuTiTmgr();
double integrate(double a, double b);
double solve(double a, double amount);
double last_time_ = 0.0; /*< Integral interval last point (discrete time) */
double total_ = 0.0; /*< Integral total between 0 and last_pointn */
- CpuTiProfile* profile_ = nullptr;
- profile::Profile* speed_profile_ = nullptr;
+ std::unique_ptr<CpuTiProfile> profile_ = nullptr;
+ profile::Profile* speed_profile_ = nullptr;
};
/**********
#include <functional>
#include <map>
+#include <memory>
#include <stdexcept>
#include <string>
#include <string>
class Config {
private:
// name -> ConfigElement:
- std::map<std::string, simgrid::config::ConfigurationElement*> options;
+ std::map<std::string, std::unique_ptr<simgrid::config::ConfigurationElement>> options;
// alias -> ConfigElement from options:
std::map<std::string, simgrid::config::ConfigurationElement*> aliases;
bool warn_for_aliases = true;
public:
Config();
- ~Config();
// No copy:
Config(Config const&) = delete;
TypedConfigurationElement<T>* variable = new TypedConfigurationElement<T>(name, std::forward<A>(a)...);
XBT_DEBUG("Register cfg elm %s (%s) of type %s @%p in set %p)", name.c_str(), variable->get_description().c_str(),
variable->get_type_name(), variable, this);
- options.insert({name, variable});
+ options.emplace(name, variable);
variable->update();
return variable;
}
{
atexit(&sg_config_finalize);
}
-Config::~Config()
-{
- XBT_DEBUG("Frees cfg set %p", this);
- for (auto const& elm : options)
- delete elm.second;
-}
inline ConfigurationElement* Config::get_dict_element(const std::string& name)
{
auto opt = options.find(name);
if (opt != options.end()) {
- return opt->second;
+ return opt->second.get();
} else {
auto als = aliases.find(name);
if (als != aliases.end()) {
void Config::help()
{
for (auto const& elm : options) {
- simgrid::config::ConfigurationElement* variable = this->options.at(elm.first);
+ simgrid::config::ConfigurationElement* variable = elm.second.get();
XBT_HELP(" %s: %s", elm.first.c_str(), variable->get_description().c_str());
XBT_HELP(" Type: %s; Current value: %s", variable->get_type_name(), variable->get_string_value().c_str());
}