#ifndef KRIMI_DINNER_ENGINE_STRINGREPOSITORY_H
#define KRIMI_DINNER_ENGINE_STRINGREPOSITORY_H

/// @file StringRepository.h
/// @brief String storage

#include <stdint.h>
#include "Hash.h"

/// A string handle
using StringHandle = uint32_t;

// Alias for compatibility
using nt_string_handle = StringHandle;

/// @brief Stores strings
class StringRepository
{
public:
    /// The default string repository
    static StringRepository* global;

    StringRepository() = default;
    StringRepository(const StringRepository& copy);
    ~StringRepository();

    /// @brief Adds a string to the string repository
    /// @param string the string
    /// @param length length in bytes
    StringHandle internStringLength(const char* string, unsigned int length);

    /// @brief Adds a string to the string repository
    /// @param string the string
    StringHandle internString(const char* string);

    /// @brief Retrieves a string value
    /// @param handle The string handle
    /// @return The string
    const char* getString(StringHandle handle);

    /// @brief Frees a string
    void releaseString(StringHandle handle);

    /// @brief Adds a string to the string repository
    /// @param a the first string
    /// @param b the second string
    StringHandle concatenateString(StringHandle a, StringHandle b);

    /// @brief Frees all strings inside the repository
    void freeAll();

private:
    uint32_t m_buffer_size;
    uint32_t m_one_past_last_char;
    char* m_buffer;
    Hash m_hash;
};

#endif