Skip to content

Commit

Permalink
replace NonCopyable and MoveOnly base classes with some macros
Browse files Browse the repository at this point in the history
 - building a DLL on windows was giving warnings because these weren't "exported"
 - could have just exported them, but I didn't really like them anyway
  • Loading branch information
jagoly committed Oct 2, 2022
1 parent b85fd7d commit 714e4fa
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 79 deletions.
8 changes: 4 additions & 4 deletions include/sqee/app/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

#include <sqee/setup.hpp>

#include <sqee/core/Utilities.hpp>
#include <sqee/core/Types.hpp>

namespace sq {

//============================================================================//

/// The SQEE Application base class.
class SQEE_API Application : NonCopyable
class SQEE_API Application
{
public: //====================================================//

/// Constructor.
Application() = default;

/// Virtual Destructor.
SQEE_COPY_DELETE(Application)
SQEE_MOVE_DELETE(Application)

virtual ~Application() = default;

//--------------------------------------------------------//
Expand Down
7 changes: 4 additions & 3 deletions include/sqee/app/AudioContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <sqee/setup.hpp>

#include <sqee/core/Utilities.hpp>

namespace sq {

//====== Forward Declarations and Enums ======================================//
Expand Down Expand Up @@ -37,12 +35,15 @@ constexpr SoundGroups operator|(SoundGroup a, SoundGroup b) { return SoundGroups
//============================================================================//

/// Handles the initialisation and playback of audio.
class SQEE_API AudioContext : NonCopyable
class SQEE_API AudioContext
{
public: //====================================================//

AudioContext();

SQEE_COPY_DELETE(AudioContext)
SQEE_MOVE_DELETE(AudioContext)

~AudioContext();

//--------------------------------------------------------//
Expand Down
6 changes: 4 additions & 2 deletions include/sqee/app/GuiSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <sqee/setup.hpp>

#include <sqee/core/Utilities.hpp>
#include <sqee/objects/Texture.hpp>
#include <sqee/vk/SwapBuffer.hpp>
#include <sqee/vk/Vulkan.hpp>
Expand All @@ -20,12 +19,15 @@ class Window;

//============================================================================//

class SQEE_API GuiSystem : NonCopyable
class SQEE_API GuiSystem
{
public: //====================================================//

GuiSystem(Window& window, InputDevices& inputDevices);

SQEE_COPY_DELETE(GuiSystem)
SQEE_MOVE_DELETE(GuiSystem)

~GuiSystem();

//--------------------------------------------------------//
Expand Down
27 changes: 18 additions & 9 deletions include/sqee/app/GuiWidgets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ constexpr ImGuiDataType_ get_data_type()

SQEE_API bool is_temp_input_open();

struct ScopeBase
{
ScopeBase() = default;
ScopeBase(const ScopeBase&) = delete;
ScopeBase& operator=(const ScopeBase&) = delete;
ScopeBase(ScopeBase&&) = delete;
ScopeBase& operator=(ScopeBase&&) = delete;
};

} // namespace detail

//----------------------------------------------------------------------------//
Expand Down Expand Up @@ -441,15 +450,15 @@ inline bool RadioButton(CStrView label, Type& ref, Type value)
//----------------------------------------------------------------------------//

/// Wrapper for Begin, End.
struct ScopeWindow final : sq::NonCopyable
struct ScopeWindow final : detail::ScopeBase
{
bool show;
ScopeWindow(CStrView name, ImGuiWindowFlags flags) : show(ImGui::Begin(name, nullptr, flags)) {}
~ScopeWindow() { ImGui::End(); }
};

/// Wrapper for Begin, End with a close button.
struct ScopeWindowClosable final : sq::NonCopyable
struct ScopeWindowClosable final : detail::ScopeBase
{
bool open = true; bool show;
ScopeWindowClosable(CStrView name, ImGuiWindowFlags flags) : show(ImGui::Begin(name, &open, flags)) {}
Expand Down Expand Up @@ -532,7 +541,7 @@ void if_TabItemChild(CStrView label, ImGuiTabItemFlags flags, Body body)
//----------------------------------------------------------------------------//

/// Wrapper for PushID, PopID.
struct ScopeID final : sq::NonCopyable
struct ScopeID final : detail::ScopeBase
{
ScopeID(const char* cstr_id) { ImGui::PushID(cstr_id); }
ScopeID(std::string_view sv_id) { ImGui::PushID(sv_id.data(), sv_id.data() + sv_id.length()); }
Expand All @@ -542,30 +551,30 @@ struct ScopeID final : sq::NonCopyable
};

/// Wrapper for PushItemWidth, PopItemWidth.
struct ScopeItemWidth final : sq::NonCopyable
struct ScopeItemWidth final : detail::ScopeBase
{
ScopeItemWidth(float width) { ImGui::PushItemWidth(width); }
~ScopeItemWidth() { ImGui::PopItemWidth(); }
};

/// Wrapper for Indent, Unindent.
struct ScopeIndent final : sq::NonCopyable
struct ScopeIndent final : detail::ScopeBase
{
ScopeIndent(float width = 0.f) : width(width) { ImGui::Indent(width); }
~ScopeIndent() { ImGui::Unindent(width); }
const float width;
};

/// Wrapper for Unindent, Indent.
struct ScopeUnindent final : sq::NonCopyable
struct ScopeUnindent final : detail::ScopeBase
{
ScopeUnindent(float width = 0.f) : width(width) { ImGui::Unindent(width); }
~ScopeUnindent() { ImGui::Indent(width); }
const float width;
};

/// Wrapper for PushFont, PopFont.
struct ScopeFont final : sq::NonCopyable
struct ScopeFont final : detail::ScopeBase
{
ScopeFont(ImFont* font) { ImGui::PushFont(font); }
ScopeFont(int fontIndex) { ImPlus::PushFont(fontIndex); }
Expand All @@ -574,15 +583,15 @@ struct ScopeFont final : sq::NonCopyable

/// Wrapper for PushStyleVar(float), PopStyleVar.
template <ImGuiStyleVar_ StyleVar>
struct ScopeStyleFloat final : sq::NonCopyable
struct ScopeStyleFloat final : detail::ScopeBase
{
ScopeStyleFloat(float value) { ImGui::PushStyleVar(StyleVar, value); }
~ScopeStyleFloat() { ImGui::PopStyleVar(); }
};

/// Wrapper for PushStyleVar(ImVec2), PopStyleVar.
template <ImGuiStyleVar_ StyleVar>
struct ScopeStyleVec final : sq::NonCopyable
struct ScopeStyleVec final : detail::ScopeBase
{
ScopeStyleVec(float x, float y) { ImGui::PushStyleVar(StyleVar, {x, y}); }
~ScopeStyleVec() { ImGui::PopStyleVar(); }
Expand Down
9 changes: 5 additions & 4 deletions include/sqee/app/InputDevices.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <sqee/setup.hpp>

#include <sqee/core/Types.hpp>
#include <sqee/core/Utilities.hpp>

//====== Forward Declarations ================================================//

Expand All @@ -19,14 +18,16 @@ struct GamepadState;

//============================================================================//

/// Access to Keyboard / Mouse / Gamepad state.
class SQEE_API InputDevices : NonCopyable
/// Access to Keyboard/Mouse/Gamepad state.
class SQEE_API InputDevices
{
public: //====================================================//

/// Constructor.
InputDevices(Window& window);

SQEE_COPY_DELETE(InputDevices)
SQEE_MOVE_DELETE(InputDevices)

//--------------------------------------------------------//

/// Check if the given key is pressed.
Expand Down
8 changes: 4 additions & 4 deletions include/sqee/app/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <sqee/setup.hpp>

#include <sqee/core/Utilities.hpp>
#include <sqee/vk/Vulkan.hpp>

namespace sq {
Expand All @@ -17,14 +16,15 @@ struct Event;
//============================================================================//

/// The SQEE Scene base class.
class SQEE_API Scene : NonCopyable
class SQEE_API Scene
{
public: //====================================================//

/// Constructor.
Scene(double tickTime);

/// Virtual Destructor.
SQEE_COPY_DELETE(Scene)
SQEE_MOVE_DELETE(Scene)

virtual ~Scene() = default;

//--------------------------------------------------------//
Expand Down
5 changes: 4 additions & 1 deletion include/sqee/app/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ namespace sq {

//============================================================================//

class SQEE_API Window : NonCopyable
class SQEE_API Window
{
public: //====================================================//

Window(const char* title, Vec2U size, const char* appName, Vec3U version);

SQEE_COPY_DELETE(Window)
SQEE_MOVE_DELETE(Window)

~Window();

//--------------------------------------------------------//
Expand Down
28 changes: 0 additions & 28 deletions include/sqee/core/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@ namespace sq {

//============================================================================//

/// Base for objects that can't be copied or moved.
struct NonCopyable
{
NonCopyable() = default;

NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;

NonCopyable(NonCopyable&&) = delete;
NonCopyable& operator=(NonCopyable&&) = delete;
};

//============================================================================//

/// Base for objects that can be moved but not copied.
struct MoveOnly
{
MoveOnly() = default;

MoveOnly(const MoveOnly&) = delete;
MoveOnly& operator=(const MoveOnly&) = delete;

MoveOnly(MoveOnly&&) = default;
MoveOnly& operator=(MoveOnly&&) = default;
};

//============================================================================//

template <class...> struct Structure;

template <class Element> struct Structure<Element>
Expand Down
8 changes: 6 additions & 2 deletions include/sqee/misc/Files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <sqee/setup.hpp>

#include <sqee/core/Types.hpp>
#include <sqee/core/Utilities.hpp>

// Note that all file paths in sqee are unix style, don't try to use dos paths.
// Windows is kind enough to work just fine with unix paths, so there's no need
Expand Down Expand Up @@ -37,8 +36,13 @@ SQEE_API void write_bytes_to_file(const String& path, const void* bytes, size_t
//============================================================================//

/// A file or string that has been split by spaces and newlines.
struct SQEE_API TokenisedFile : MoveOnly
struct SQEE_API TokenisedFile
{
TokenisedFile() = default;

SQEE_COPY_DELETE(TokenisedFile)
SQEE_MOVE_DEFAULT(TokenisedFile)

/// Load a text file and tokenise it.
static TokenisedFile from_file(const String& path);

Expand Down
8 changes: 6 additions & 2 deletions include/sqee/misc/ResourceCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <sqee/setup.hpp>

#include <sqee/core/Utilities.hpp>
#include <sqee/debug/Assert.hpp>
#include <sqee/debug/Logging.hpp>
#include <sqee/misc/ResourceHandle.hpp>
Expand All @@ -16,12 +15,17 @@ namespace sq {

/// Class that provides caching of a type of resource.
template <class Key, class Type>
class ResourceCache final : NonCopyable
class ResourceCache final
{
public: //====================================================//

using Factory = std::function<Type(const Key&)>;

ResourceCache() = default;

SQEE_COPY_DELETE(ResourceCache)
SQEE_MOVE_DELETE(ResourceCache)

/// Set the callable to use to create new resources.
void assign_factory(Factory factory)
{
Expand Down
8 changes: 6 additions & 2 deletions include/sqee/misc/ResourceHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <sqee/setup.hpp>

#include <sqee/core/Utilities.hpp>
#include <sqee/debug/Assert.hpp>

namespace sq {
Expand All @@ -14,8 +13,13 @@ namespace sq {

/// For internal use by ResourceCache and Handle.
template <class Key, class Type>
struct Resource final : NonCopyable
struct Resource final
{
Resource() = default;

SQEE_COPY_DELETE(Resource)
SQEE_MOVE_DELETE(Resource)

const Key* key;
std::unique_ptr<Type> data;
size_t count;
Expand Down
Loading

0 comments on commit 714e4fa

Please sign in to comment.