🗄 VolumeList-Cpp 🗄

This project allows to add a notion of volume in contiguous containers in memory. An interesting example of use would be a timetable application.

Installation — WORK IN PROGRESS 👨‍💻

Usage 📜

Essential methods ⭐

VolumeList(size_t max_volume, bool is_dynamic_size = false); // Constructor
void append(T& element, size_t volume);
void insert(T& element, size_t min_position, size_t volume);
void remove(size_t index);


Creation of a VolumeList of type string, with a maximum volume of 100 units and a non dynamics size.

auto volume_list = VolumeList<std::string>{100};  // type can be anything.


The append method takes the element to be added at the end of the list and its volume. Here we add a string with a volume of 10 to our list and a string with a volume of 20.


auto elem1 = std::string("Hi there!");
auto elem2 = std::string("I hope you enjoy it");
volume_list.append(elem1, 10);
volume_list.append(elem2, 20);

List status (std::cout << volume_list):

Element: Hi there!
Position: [0, 9]
Volume: 10
Element: I hope you enjoy it
Position: [9, 29]
Volume: 20


Webp net-gifmaker

The insert method takes the element to insert, its volume, and the place where it starts in the volume list. If there is already an element at this position, it is shifted.


auto elem1 = std::string("First");
auto elem2 = std::string("Second");
auto elem3 = std::string("Third");
auto elem4 = std::string("Fourth");

volune_list.insert(elem1, 0, 10);
volume_list.insert(elem2, 2, 7);
volume_list.insert(elem3, 2, 9);
volune_list.insert(elem4, 0, 5);

List status (std::cout << volume_list):

Element: Fourth
Position: [0, 4]
Volume: 5
Element: Third
Position: [4, 13]
Volume: 9
Element: Second
Position: [13, 20]
Volume: 7
Element: First
Position: [20, 30]
Volume: 10


Webp net-gifmaker (1)

The remove function allows to remove an element from the list with its index, it works like a classic remove.


auto elem1 = std::string("Bye you :c");
auto elem2 = std::string("Hi there !");
volume_list.append(elem1, 10);
volune_list.append(elem2, 10);


List status (std::cout << volume_list):

Element: Hi there !
Position: [9, 19]
Volume: 10

Methods that may be useful to you 🌟

T& operator[](size_t index);
VolumeWrapper<T>& get_volume_at(size_t index);

size_t get_max_volume() const;
size_t get_current_volume() const;
size_t get_element_number() const;
size_t get_remaining_volume() const;
bool get_is_dynamic_size() const;

std::vector<VolumeWrapper<T>>::const_iterator begin() const;
std::vector<VolumeWrapper<T>>::iterator begin();
std::vector<VolumeWrapper<T>>::const_iterator end() const;
std::vector<VolumeWrapper<T>>::iterator end();

Essential Methods — VolumeWrapper ⭐

VolumeWrapper(std::shared_ptr<T> element, size_t min_position, size_t volume);
T& get_element() const;
size_t get_min_position() const;
size_t get_max_position() const;
size_t get_volume() const;

Compatibility with STL functions — WORK IN PROGRESS 👨‍💻

Code documentation — WORK IN PROGRESS 👨‍💻


View Github