Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidorenkov #3

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@

# cmake-build-debug directory
cmake-build-debug/
.vs/
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set(CMAKE_CXX_STANDARD 14)

add_subdirectory(allocator)
add_subdirectory(arithmetic)
add_subdirectory(associative_container)
#add_subdirectory(associative_container)
add_subdirectory(common)
add_subdirectory(logger)
add_subdirectory(logger)
102 changes: 81 additions & 21 deletions allocator/allocator_global_heap/src/allocator_global_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,108 @@

#include "../include/allocator_global_heap.h"

allocator_global_heap::allocator_global_heap(
logger *logger)
allocator_global_heap::allocator_global_heap(logger* logger) : _logger(logger)
{
throw not_implemented("allocator_global_heap::allocator_global_heap(logger *)", "your code should be here...");
if (_logger)
{
_logger->log("allocator_global_heap called", logger::severity::trace);
}
}

allocator_global_heap::~allocator_global_heap()
{
throw not_implemented("allocator_global_heap::~allocator_global_heap()", "your code should be here...");
if (_logger)
{
_logger->log("~allocator_global_heap called", logger::severity::trace);
}
}

allocator_global_heap::allocator_global_heap(
allocator_global_heap &&other) noexcept
allocator_global_heap::allocator_global_heap(allocator_global_heap&& other) noexcept : _logger(other._logger)
{
throw not_implemented("allocator_global_heap::allocator_global_heap(allocator_global_heap &&) noexcept", "your code should be here...");
if (_logger)
{
_logger->log("allocator_global_heap(allocator_global_heap &&) called", logger::severity::trace);
}
other._logger = nullptr;
}

allocator_global_heap &allocator_global_heap::operator=(
allocator_global_heap &&other) noexcept
allocator_global_heap& allocator_global_heap::operator=(allocator_global_heap&& other) noexcept
{
throw not_implemented("allocator_global_heap &allocator_global_heap::operator=(allocator_global_heap &&) noexcept", "your code should be here...");
if (this != &other)
{
if (_logger)
{
_logger->log("allocator_global_heap::operator=(allocator_global_heap &&) called", logger::severity::trace);
}
_logger = other._logger;
other._logger = nullptr;
}
return *this;
}

[[nodiscard]] void *allocator_global_heap::allocate(
size_t value_size,
size_t values_count)
[[nodiscard]] void* allocator_global_heap::allocate(size_t value_size, size_t values_count)
{
throw not_implemented("[[nodiscard]] void *allocator_global_heap::allocate(size_t, size_t)", "your code should be here...");
if (_logger)
{
_logger->log("allocate called", logger::severity::debug);
}

size_t total_size = value_size * values_count;

try
{
void* memory = ::operator new(total_size);
if (_logger)
{
_logger->log("Memory allocated: " + std::to_string(total_size) + " bytes", logger::severity::warning);
}
return memory;
}
catch (const std::bad_alloc& e)
{
if (_logger)
{
_logger->log("Failed to allocate memory: " + std::string(e.what()), logger::severity::error);
}
throw;
}
}

void allocator_global_heap::deallocate(
void *at)
void allocator_global_heap::deallocate(void* at)
{
throw not_implemented("void allocator_global_heap::deallocate(void *)", "your code should be here...");
if (_logger)
{
_logger->log("deallocate called", logger::severity::debug);
}

if (!at)
{
if (_logger)
{
_logger->log("Trying to deallocate a null pointer", logger::severity::error);
}
throw std::logic_error("Trying to deallocate a null pointer");
}

if (_logger)
{
_logger->log("Memory block state before deallocation: " + std::string(reinterpret_cast<const char*>(at), 16), logger::severity::debug);
}

::operator delete(at);

if (_logger)
{
_logger->log("Memory deallocated", logger::severity::trace);
}
}

inline logger *allocator_global_heap::get_logger() const
inline logger* allocator_global_heap::get_logger() const
{
throw not_implemented("inline logger *allocator_global_heap::get_logger() const", "your code should be here...");
return _logger;
}

inline std::string allocator_global_heap::get_typename() const noexcept
{
throw not_implemented("inline std::string allocator_global_heap::get_typename() const noexcept", "your code should be here...");
}
return typeid(*this).name();
}
39 changes: 28 additions & 11 deletions logger/client_logger/include/client_logger.h
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
#ifndef MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_H
#define MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_H

#include <logger.h>
#include <map>
#include <fstream>
#include "client_logger_builder.h"
#include "logger.h"

class client_logger final:
class client_logger final :
public logger
{

friend class client_logger_builder;

private:

static std::map <std::string, std::pair<std::ofstream*, int>> logger_info;
std::map<std::string, unsigned char> file_info;
std::string format;

private:
std::string getFormatString(const std::string& text,
logger::severity severity) const;

private:
client_logger(std::map<std::string, unsigned char> file_info, std::string file_name);

public:

client_logger(
client_logger const &other);
client_logger const& other);

client_logger &operator=(
client_logger const &other);
client_logger& operator=(
client_logger const& other);

client_logger(
client_logger &&other) noexcept;
client_logger&& other) noexcept;

client_logger &operator=(
client_logger &&other) noexcept;
client_logger& operator=(
client_logger&& other) noexcept;

~client_logger() noexcept final;

public:

[[nodiscard]] logger const *log(
const std::string &message,
[[nodiscard]] logger const* log(
const std::string& message,
logger::severity severity) const noexcept override;

};

#endif //MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_H
#endif //MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_H
38 changes: 23 additions & 15 deletions logger/client_logger/include/client_logger_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,54 @@
#define MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_BUILDER_H

#include <logger_builder.h>
#include <client_logger.h>
#include <map>

class client_logger_builder final:
class client_logger_builder final :
public logger_builder


{
private:
std::map<std::string, unsigned char> file_info;
std::string format;

public:
logger_builder* set_format(const std::string& format_str);

client_logger_builder();

client_logger_builder(
client_logger_builder const &other);
client_logger_builder const& other);

client_logger_builder &operator=(
client_logger_builder const &other);
client_logger_builder& operator=(
client_logger_builder const& other);

client_logger_builder(
client_logger_builder &&other) noexcept;
client_logger_builder&& other) noexcept;

client_logger_builder &operator=(
client_logger_builder &&other) noexcept;
client_logger_builder& operator=(
client_logger_builder&& other) noexcept;

~client_logger_builder() noexcept override;

public:

logger_builder *add_file_stream(
std::string const &stream_file_path,
logger_builder* add_file_stream(
std::string const& stream_file_path,
logger::severity severity) override;

logger_builder *add_console_stream(
logger_builder* add_console_stream(
logger::severity severity) override;

logger_builder* transform_with_configuration(
std::string const &configuration_file_path,
std::string const &configuration_path) override;
std::string const& configuration_file_path,
std::string const& configuration_path) override;

logger_builder *clear() override;
logger_builder* clear() override;

[[nodiscard]] logger *build() const override;
[[nodiscard]] logger* build() const override;

};

#endif //MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_BUILDER_H
#endif //MATH_PRACTICE_AND_OPERATING_SYSTEMS_CLIENT_LOGGER_BUILDER_H
Loading