Commit 7ec3baa6 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

next17

parent 40cda3ee
Pipeline #2318 failed with stage
in 59 seconds
......@@ -310,11 +310,11 @@ data_array<T, Identifier>::alloc()
Do_alloc<T, Identifier>(items[new_index].item, std::is_trivial<T>());
std::printf(
"new index: %d next key: %u and ID: %lu\n",
new_index,
next_key,
static_cast<long unsigned int>(make_id<Identifier>(next_key, new_index)));
std::printf("new index: %d next key: %u and ID: %lu\n",
new_index,
next_key,
static_cast<long unsigned int>(
make_id<Identifier>(next_key, new_index)));
items[new_index].id = make_id<Identifier>(next_key, new_index);
next_key = make_next_key<Identifier>(next_key);
......
......@@ -53,7 +53,8 @@ public:
bits_expects(size > 0);
}
void emplace(const identifier_type id, const referenced_type value) noexcept
void emplace(const identifier_type id,
const referenced_type value) noexcept
{
bits_expects(bits::valid(id));
......@@ -112,7 +113,8 @@ struct multi_linker_node
template<typename Identifier,
typename Referenced,
typename IdentifierAllocator = std::allocator<int>,
typename NodeAllocator = std::allocator<multi_linker_node<Referenced>>>
typename NodeAllocator =
std::allocator<multi_linker_node<Referenced>>>
class multi_linker
{
public:
......@@ -135,15 +137,16 @@ private:
class view
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = Identifier;
using difference_type = std::ptrdiff_t;
using pointer = typename DataArray::T*;
using reference = typename DataArray::T&;
class iterator
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = Identifier;
using difference_type = std::ptrdiff_t;
using pointer = typename DataArray::value_type*;
using reference = typename DataArray::value_type&;
private:
this_type* list = nullptr;
DataArray* dataarray = nullptr;
......@@ -151,6 +154,8 @@ private:
public:
iterator() noexcept = default;
iterator(const iterator&) noexcept = default;
iterator& operator=(const iterator&) noexcept = default;
iterator(this_type& list_,
DataArray& dataarray_,
......@@ -235,13 +240,13 @@ private:
pointer operator->() const noexcept
{
return dataarray->try_to_get(list[elem].id);
return dataarray->try_to_get(list->list[elem].id);
}
reference operator*() const noexcept
{
auto* ptr = dataarray->try_to_get(list[elem].id);
assert(ptr);
auto* ptr = dataarray->try_to_get(list->list[elem].id);
bits_assert(ptr);
return *ptr;
}
......@@ -258,8 +263,8 @@ private:
friend bool operator==(const iterator& lhs,
const iterator& rhs) noexcept
{
return lhs.list == rhs.list && lhs.dataarray == rhs.dataarray &&
lhs.elem == rhs.elem;
return lhs.list == rhs.list &&
lhs.dataarray == rhs.dataarray && lhs.elem == rhs.elem;
}
friend bool operator!=(const iterator& lhs,
......@@ -275,7 +280,9 @@ private:
int elem = -1;
public:
view(this_type& list_, DataArray& dataarray_, int elem_) noexcept
view(this_type& list_,
DataArray& dataarray_,
Identifier elem_) noexcept
: list(list_)
, dataarray(dataarray_)
, elem(elem_)
......@@ -290,16 +297,6 @@ private:
{
return iterator(list, dataarray, -1);
}
const_iterator begin() const
{
return const_iterator(list, dataarray, elem);
}
const_iterator end() const
{
return const_iterator(list, dataarray, -1);
}
};
public:
......@@ -331,6 +328,12 @@ public:
list.clear();
}
template<typename DataArray>
view<DataArray> get_view(identifier_type id, DataArray& dataarray) noexcept
{
return view(*this, dataarray, id);
}
void emplace(Identifier ID, Referenced value) noexcept
{
bits_expects(bits::valid(ID));
......@@ -351,19 +354,6 @@ public:
map[index] = new_pos;
}
template<typename DataArray>
auto begin(DataArray* array, Identifier head) noexcept
{
auto index = bits::get_index(head);
return iterator(this, array, index);
}
template<typename DataArray>
auto end(DataArray* array) noexcept
{
return iterator(this, array, -1);
}
void destroy(Identifier ID)
{
bits_expects(bits::valid(ID));
......
......@@ -329,7 +329,8 @@ struct Ball
{
return t;
}
void output() {}
void output()
{}
};
/* to be declare in model.cpp in DECLARE_DYNAMICS for example */
......@@ -552,16 +553,10 @@ struct Vpz
while (conditions.next(cond)) {
fprintf(&f, " <condition name=\"%s\">\n", cond->name.c_str());
for (auto it = condition_named_values.begin(
&conditions, conditions.get_id(*cond)),
et = condition_named_values.end(&conditions);
it != et;
++it) {
auto* namedvalue = named_values.try_to_get(*it);
if (namedvalue) {
write(f, *namedvalue);
}
}
auto view = condition_named_values.get_view(
conditions.get_id(*cond), named_values);
for (auto it = view.begin(), et = view.end(); it != et; ++it)
write(f, *it);
fprintf(&f, " </condition>\n");
}
......@@ -593,12 +588,15 @@ struct Vpz
fprintf(&f, " <structures>\n");
int space = 2;
if (model.type == Model::model_type::atomic) {
if (model.input_slot_number == 0 && model.output_slot_number == 0) {
fprintf(
&f, " <model name=\"%s\" type=\"atomic\" />\n", model.name);
if (model.input_slot_number == 0 &&
model.output_slot_number == 0) {
fprintf(&f,
" <model name=\"%s\" type=\"atomic\" />\n",
model.name.c_str());
} else {
fprintf(
&f, " <model name=\"%s\" type=\"atomic\">\n", model.name);
fprintf(&f,
" <model name=\"%s\" type=\"atomic\">\n",
model.name.c_str());
if (model.input_slot_number) {
fprintf(&f, "<in>\n");
fprintf(&f, "</in>\n");
......@@ -618,10 +616,11 @@ struct Vpz
void write(FILE& f)
{
fprintf(&f,
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
"<!DOCTYPE vle_project PUBLIC \"-//VLE TEAM//DTD Strict // EN\""
"\"https://www.vle-project.org/vle-1.1.0.dtd\">\n");
fprintf(
&f,
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
"<!DOCTYPE vle_project PUBLIC \"-//VLE TEAM//DTD Strict // EN\""
"\"https://www.vle-project.org/vle-1.1.0.dtd\">\n");
fprintf(&f,
"<vle_project version=\"%s\" date=\"%s\" author=\"%s\">\n",
......@@ -716,36 +715,18 @@ struct Vpz
{
auto id_model = models.get_id(model);
for (auto it = model_input_ports.begin(&models, id_model),
et = model_input_ports.end(&models);
it != et;
++it) {
auto* port = input_ports.try_to_get(*it);
if (port)
input_ports.free(*port);
}
for (auto& port : model_input_ports.get_view(id_model, input_ports))
input_ports.free(port);
for (auto it = model_output_ports.begin(&models, id_model),
et = model_output_ports.end(&models);
it != et;
++it) {
auto* port = output_ports.try_to_get(*it);
if (port)
output_ports.free(*port);
}
for (auto& port : model_output_ports.get_view(id_model, output_ports))
output_ports.free(port);
model_output_ports.destroy(id_model);
model_output_ports.destroy(id_model);
if (model.type == Model::model_type::coupled) {
for (auto it = model_children.begin(&models, id_model),
et = model_children.end(&models);
it != et;
++it) {
auto* model = models.try_to_get(*it);
if (model)
destroy(*model);
}
for (auto& mdl : model_children.get_view(id_model, models))
destroy(mdl);
model_children.destroy(id_model);
model_connections.destroy(id_model);
......@@ -898,13 +879,13 @@ struct Vpz
real64.free(*x);
}
case value_type::vec2_32: {
auto* x =
vec2_32.try_to_get(named_value_links[named_values.get_id(value)]);
auto* x = vec2_32.try_to_get(
named_value_links[named_values.get_id(value)]);
vec2_32.free(*x);
}
case value_type::vec3_32: {
auto* x =
vec3_32.try_to_get(named_value_links[named_values.get_id(value)]);
auto* x = vec3_32.try_to_get(
named_value_links[named_values.get_id(value)]);
vec3_32.free(*x);
}
case value_type::none:
......@@ -1014,25 +995,20 @@ struct Vpz
void append(const Condition& condition, NamedValue& value)
{
auto cond_id = conditions.get_id(condition);
auto id = conditions.get_id(condition);
auto named_value_id = named_values.get_id(value);
condition_named_values.emplace(cond_id, named_value_id);
condition_named_values.emplace(id, named_value_id);
}
void destroy(Condition& condition)
{
auto cond_id = conditions.get_id(condition);
auto id = conditions.get_id(condition);
for (auto it = condition_named_values.begin(&conditions, cond_id),
et = condition_named_values.end(&conditions);
it != et;
++it) {
auto* named_value = named_values.try_to_get(*it);
destroy(*named_value);
}
for (auto& nv : condition_named_values.get_view(id, named_values))
destroy(nv);
condition_named_values.destroy(cond_id);
condition_named_values.destroy(id);
}
Port& add_input_port(const Model& model, std::string name)
......@@ -1093,7 +1069,7 @@ struct Vpz
} // vle
int
main(int /* argc */, char* /* argv */[])
main(int /* argc */, char* /* argv */ [])
{
std::cout << "ID: get_max_key: " << bits::get_max_key<vle::ID>() << '\n';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment