Skip to content

Commit

Permalink
Add model class
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed May 11, 2024
1 parent dfd3ec8 commit ecee935
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
95 changes: 95 additions & 0 deletions source/core/inc/tactile/core/model/model.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/base/prelude.hpp"
#include "tactile/core/document/document.hpp"
#include "tactile/core/document/document_manager.hpp"

namespace tactile {

struct Settings;

namespace ui {
class Language;
} // namespace ui

/// \addtogroup Model
/// \{

/**
* Provides the top-level API for the core document model.
*
* \details
* Due to the nature of how Dear ImGui works, the model only allows using one
* language per editor session. This is to avoid issues regarding the handling
* of translated strings.
*/
class Model final
{
public:
/**
* Creates a model.
*
* \param settings The associated settings.
* \param language The language that will be used throughout this session.
*/
Model(const Settings* settings, const ui::Language* language);

/**
* Returns the associated document manager.
*
* \return
* A document manager.
*/
[[nodiscard]]
auto get_document_manager() -> DocumentManager&;

/**
* \copydoc get_documents()
*/
[[nodiscard]]
auto get_document_manager() const -> const DocumentManager&;

/**
* Returns the currently active document, if any.
*
* \return
* A pointer to the active document; a null pointer if there is none.
*/
[[nodiscard]]
auto get_current_document() -> IDocument*;

/**
* \copydoc get_current_document()
*/
[[nodiscard]]
auto get_current_document() const -> const IDocument*;

/**
* Returns the associated settings.
*
* \return
* A pointer to the settings.
*/
[[nodiscard]]
auto get_settings() const -> const Settings&;

/**
* Returns the language used in this session.
*
* \return
* A language.
*/
[[nodiscard]]
auto get_language() const -> const ui::Language&;

private:
const Settings* mSettings {};
const ui::Language* mLanguage {};
DocumentManager mDocuments {};
};

/// \}

} // namespace tactile
44 changes: 44 additions & 0 deletions source/core/src/tactile/core/model/model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/model/model.hpp"

#include "tactile/core/debug/validation.hpp"

namespace tactile {

Model::Model(const Settings* settings, const ui::Language* language)
: mSettings {require_not_null(settings, "null settings")},
mLanguage {require_not_null(language, "null language")}
{}

auto Model::get_document_manager() -> DocumentManager&
{
return mDocuments;
}

auto Model::get_document_manager() const -> const DocumentManager&
{
return mDocuments;
}

auto Model::get_current_document() -> IDocument*
{
return mDocuments.get_current_document();
}

auto Model::get_current_document() const -> const IDocument*
{
return mDocuments.get_current_document();
}

auto Model::get_settings() const -> const Settings&
{
return *mSettings;
}

auto Model::get_language() const -> const ui::Language&
{
return *mLanguage;
}

} // namespace tactile

0 comments on commit ecee935

Please sign in to comment.