Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/openvic-simulation/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <spdlog/spdlog.h>

#include "openvic-simulation/core/memory/OrderedSet.hpp"
#include "openvic-simulation/dataloader/Dataloader.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/Logger.hpp"

using namespace OpenVic;
Expand Down Expand Up @@ -76,7 +76,7 @@ bool GameManager::load_mods(memory::vector<memory::string> const& mods_to_find)

bool ret = true;

vector_ordered_set<Mod const*> load_list;
memory::vector_ordered_set<Mod const*> load_list;

/* Check loaded mod descriptors for requested mods, using either full name or user directory name
* (Historical Project Mod 0.4.6 or HPM both valid, for example), and load them plus their dependencies.
Expand All @@ -95,7 +95,7 @@ bool GameManager::load_mods(memory::vector<memory::string> const& mods_to_find)
}

Mod const* mod_ptr = &*it;
vector_ordered_set<Mod const*> dependencies = mod_ptr->generate_dependency_list(&ret);
memory::vector_ordered_set<Mod const*> dependencies = mod_ptr->generate_dependency_list(&ret);
if(!ret) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/InstanceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <function2/function2.hpp>

#include "openvic-simulation/console/ConsoleInstance.hpp"
#include "openvic-simulation/core/memory/FlagStrings.hpp"
#include "openvic-simulation/country/CountryInstanceManager.hpp"
#include "openvic-simulation/country/CountryInstanceDeps.hpp"
#include "openvic-simulation/diplomacy/CountryRelation.hpp"
Expand All @@ -21,7 +22,6 @@
#include "openvic-simulation/politics/PoliticsInstanceManager.hpp"
#include "openvic-simulation/population/PopDeps.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/FlagStrings.hpp"
#include "openvic-simulation/utility/ThreadPool.hpp"
#include "openvic-simulation/utility/Containers.hpp"

Expand Down Expand Up @@ -50,7 +50,7 @@ namespace OpenVic {
ResourceGatheringOperationDeps rgo_deps;
ProvinceInstanceDeps province_instance_deps;

FlagStrings PROPERTY_REF(global_flags);
memory::FlagStrings PROPERTY_REF(global_flags);

CountryInstanceManager PROPERTY_REF(country_instance_manager);
UnitInstanceManager PROPERTY_REF(unit_instance_manager);
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/console/ConsoleInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <fmt/color.h>
#include <fmt/core.h>

#include "openvic-simulation/core/memory/StringMap.hpp"
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/Containers.hpp"
#include "openvic-simulation/utility/Getters.hpp"

Expand Down Expand Up @@ -98,7 +98,7 @@ namespace OpenVic {
Technology const* validate_tech_name(std::string_view value_string);

private:
string_map_t<execute_command_func_t> commands;
memory::string_map_t<execute_command_func_t> commands;

write_func_t write_func;

Expand Down
15 changes: 15 additions & 0 deletions src/openvic-simulation/core/container/CaseContainer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "openvic-simulation/core/template/Concepts.hpp"

namespace OpenVic {
/* Intermediate struct that "remembers" Case, instead of just decomposing it into its hash and equal components,
* needed so that templates can deduce the Case with which a type was defined. */
template<template<typename...> typename Container, string_map_case Case, typename... Args>
struct template_case_container_t : Container<Args..., typename Case::hash, typename Case::equal> {
using container_t = Container<Args..., typename Case::hash, typename Case::equal>;
using container_t::container_t;

using case_t = Case;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <vector>

#include "openvic-simulation/core/Assert.hpp"
#include "openvic-simulation/types/BasicIterator.hpp"
#include "openvic-simulation/utility/Allocator.hpp"
#include "openvic-simulation/core/container/BasicIterator.hpp"
#include "openvic-simulation/core/Allocator.hpp"
#include "openvic-simulation/core/Compare.hpp"
#include "openvic-simulation/core/template/Concepts.hpp"
#include "openvic-simulation/core/Typedefs.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include <cassert>
#include <cstddef>
#include <memory>
#include <type_traits>
#include <utility>

#include "openvic-simulation/core/Assert.hpp"
#include "openvic-simulation/core/template/Concepts.hpp"
#include "openvic-simulation/core/Typedefs.hpp"

namespace OpenVic::_detail {
namespace OpenVic {
//fixed capacity + not movable + not copyable
template <typename T, typename Allocator = std::allocator<T>>
class FixedVector {
Expand All @@ -27,6 +28,7 @@ namespace OpenVic::_detail {
using reference = T&;
using size_type = size_t;
using value_type = T;
using allocator_type = Allocator;

constexpr size_t size() const { return _size; }
constexpr size_t capacity() const { return _max_size; }
Expand All @@ -39,15 +41,21 @@ namespace OpenVic::_detail {
* @brief Creates an uninitialised vector with fixed capacity
*/
explicit FixedVector(const size_t capacity)
: FixedVector(capacity, Allocator()) {}

FixedVector(const size_t capacity, std::type_identity_t<Allocator> const& alloc)
: _max_size(capacity),
_size(0),
_allocator(),
_allocator(alloc),
_data_start_ptr(allocator_traits::allocate(_allocator, capacity)) {}

FixedVector(const size_t size, T const& value_for_all_indices)
: FixedVector(size, value_for_all_indices, Allocator()) {}

FixedVector(const size_t size, T const& value_for_all_indices, std::type_identity_t<Allocator> const& alloc)
: _max_size(size),
_size(size),
_allocator(),
_allocator(alloc),
_data_start_ptr(allocator_traits::allocate(_allocator, size)) {
std::fill(_data_start_ptr, _data_start_ptr + size, value_for_all_indices);
}
Expand All @@ -59,9 +67,19 @@ namespace OpenVic::_detail {
// The type must be constructible from the generator's single return value
&& std::constructible_from<T, decltype(std::declval<GeneratorTemplateType>()(std::declval<size_t>()))>
FixedVector(const size_t size, GeneratorTemplateType&& generator)
: FixedVector(size, std::forward<GeneratorTemplateType>(generator), Allocator()) {
}

//Generator (size_t i) -> U (where T is constructable from U)
template<typename GeneratorTemplateType>
// The generator must NOT return a tuple
requires (!specialization_of<std::remove_cvref_t<std::invoke_result_t<GeneratorTemplateType, size_t>>, std::tuple>)
// The type must be constructible from the generator's single return value
&& std::constructible_from<T, decltype(std::declval<GeneratorTemplateType>()(std::declval<size_t>()))>
FixedVector(const size_t size, GeneratorTemplateType&& generator, std::type_identity_t<Allocator> const& alloc)
: _max_size(size),
_size(size),
_allocator(),
_allocator(alloc),
_data_start_ptr(allocator_traits::allocate(_allocator, size)) {
for (size_t i = 0; i < size; ++i) {
allocator_traits::construct(
Expand All @@ -88,9 +106,28 @@ namespace OpenVic::_detail {
};
}
FixedVector(const size_t size, GeneratorTemplateType&& generator)
: FixedVector(size, std::forward<GeneratorTemplateType>(generator), Allocator()) {
}

//Generator (size_t i) -> std::tuple<Args...> (where T is constructable from Args)
template<typename GeneratorTemplateType>
// The generator must return a tuple
requires specialization_of<std::remove_cvref_t<std::invoke_result_t<GeneratorTemplateType, size_t>>, std::tuple>
// The tuple must be constructible into a T
&& requires(GeneratorTemplateType&& generator) {
{
std::apply(
[](auto&&... args) {
T obj{std::forward<decltype(args)>(args)...};
},
generator(std::declval<size_t>())
)
};
}
FixedVector(const size_t size, GeneratorTemplateType&& generator, std::type_identity_t<Allocator> const& alloc)
: _max_size(size),
_size(size),
_allocator(),
_allocator(alloc),
_data_start_ptr(allocator_traits::allocate(_allocator, size)) {
for (size_t i = 0; i < size; ++i) {
std::apply(
Expand All @@ -115,7 +152,7 @@ namespace OpenVic::_detail {
clear();
allocator_traits::deallocate(_allocator, _data_start_ptr, _max_size);
}

using iterator = T*;
using const_iterator = const T*;

Expand All @@ -126,7 +163,7 @@ namespace OpenVic::_detail {
iterator end() { return begin() + _size; }
const_iterator end() const { return begin() + _size; }
const_iterator cend() const { return cbegin() + _size; }

using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;

Expand Down Expand Up @@ -198,14 +235,9 @@ namespace OpenVic::_detail {
}
_size = 0;
}
};
}

#include <foonathan/memory/std_allocator.hpp>

#include "openvic-simulation/utility/MemoryTracker.hpp"

namespace OpenVic::memory {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
using FixedVector = _detail::FixedVector<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
allocator_type get_allocator() const {
return _allocator;
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "openvic-simulation/core/template/Concepts.hpp"
#include "openvic-simulation/utility/Getters.hpp"
#include "openvic-simulation/utility/Logger.hpp"
#include "openvic-simulation/core/memory/StringMap.hpp"

namespace OpenVic {
/* Callbacks for trying to add duplicate keys via UniqueKeyRegistry::add_item */
Expand Down Expand Up @@ -174,7 +175,7 @@ namespace OpenVic {
private:
using StorageInfo = _StorageInfo<item_type>;
using internal_storage_index_type = typename StorageInfo::index_type;
using identifier_index_map_t = template_string_map_t<internal_storage_index_type, Case>;
using identifier_index_map_t = memory::template_string_map_t<internal_storage_index_type, Case>;

public:
using storage_type = typename StorageInfo::storage_type;
Expand Down
Loading