Skip to content

Commit

Permalink
used using enum everywhere
Browse files Browse the repository at this point in the history
Excluding the ColumnType because it have a lot of names which can
collide (it needs more work).

Excluding the IncrementOrDecrement in Model as using enum can't name
dependent type.
See: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html
  • Loading branch information
silverqx committed Aug 7, 2024
1 parent 3b489eb commit 433c4ac
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
18 changes: 7 additions & 11 deletions include/orm/tiny/concerns/buildssoftdeletes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,13 @@ namespace Concerns
/*! Restore all trashed models (call update on deleted_at column, set to null). */
std::tuple<int, TSqlQuery> restore();

/*! Alias for the WithoutTrashed constraint. */
constexpr static auto WithoutTrashed = TrashedType::WITHOUT_TRASHED;
/*! Alias for the WithTrashed constraint. */
constexpr static auto WithTrashed = TrashedType::WITH_TRASHED;
/*! Alias for the OnlyTrashed constraint. */
constexpr static auto OnlyTrashed = TrashedType::ONLY_TRASHED;

/*! Get the currently applied soft deletes constraint on the TinyBuilder. */
inline TrashedType currentSoftDeletes() const noexcept;

protected:
/*! Expose the TrashedType enum. */
using enum TrashedType;

/*! Get the "deleted at" column for the builder (fully qualified if joins
are defined). */
QString getDeletedAtColumn(Builder<Model> &builder) const;
Expand All @@ -96,7 +92,7 @@ namespace Concerns
Builder<Model> &applySoftDeletes();

/*! Stores the currently applied soft deletes constraint on the TinyBuilder. */
TrashedType m_trashed = WithoutTrashed;
TrashedType m_trashed = WITHOUT_TRASHED;
/*! Is the default soft deletes constraint on the TinyBuilder enabled? */
bool m_withSoftDeletes = false;

Expand Down Expand Up @@ -162,7 +158,7 @@ namespace Concerns
Builder<Model> &
BuildsSoftDeletes<Model, T>::withoutTrashed()
{
m_trashed = WithoutTrashed;
m_trashed = WITHOUT_TRASHED;

/* Disable the default soft deletes constraint on the TinyBuilder because
manually overridden and we are applying another whereNull clause here. */
Expand All @@ -182,7 +178,7 @@ namespace Concerns
if (!withTrashed)
return withoutTrashed();

m_trashed = WithTrashed;
m_trashed = WITH_TRASHED;

// Disable the default soft deletes constraint on the TinyBuilder (withoutTrashed)
disableSoftDeletes();
Expand All @@ -194,7 +190,7 @@ namespace Concerns
Builder<Model> &
BuildsSoftDeletes<Model, T>::onlyTrashed()
{
m_trashed = OnlyTrashed;
m_trashed = ONLY_TRASHED;

/* Disable the default soft deletes constraint on the TinyBuilder because
manually overridden and we are applying another whereNotNull clause here. */
Expand Down
4 changes: 4 additions & 0 deletions include/orm/tiny/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,17 @@ namespace Orm::Tiny
/*! Method to call in the incrementOrDecrement(). */
enum struct IncrementOrDecrement : quint8
{
/*! Call the increment() method. */
INCREMENT,
/*! Call the decrement() method. */
DECREMENT,
};
/*! Call the increment() method. */
constexpr static auto Increment = IncrementOrDecrement::INCREMENT;
/*! Call the decrement() method. */
constexpr static auto Decrement = IncrementOrDecrement::DECREMENT;
/* Don't use using enum here as it can't name dependent type.
See: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1099r5.html */

/*! Run the increment or decrement method on the model. */
template<typename T> requires std::is_arithmetic_v<T>
Expand Down
8 changes: 2 additions & 6 deletions tom/include/tom/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,8 @@ namespace Concerns
/*! Show a command not defined error wall. */
ShowErrorWall,
};
/*! Show all commands list using the list command. */
constexpr static CommandNotFound
ShowCommandsList = CommandNotFound::ShowCommandsList;
/*! Show a command not defined error wall. */
constexpr static CommandNotFound
ShowErrorWall = CommandNotFound::ShowErrorWall;
/*! Expose the CommandNotFound enum. */
using enum CommandNotFound;

/*! Get the command name including the guess command name logic. */
QString getCommandName(const QString &name, CommandNotFound notFound);
Expand Down
14 changes: 8 additions & 6 deletions tom/include/tom/commands/completecommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,20 @@ namespace Tom::Commands
getCommandOptionsSignature(const std::optional<QString> &command) const;

/*! Option type (long/short). */
enum struct OptionType : qint8
enum struct OptionType : quint8
{
UNDEFINED = -1,
/*! Consider both long and short option arguments. */
ANY,
/*! Long option argument. */
LONG,
/*! Short option argument. */
SHORT,
};
constexpr static auto UNDEFINED = OptionType::UNDEFINED;
constexpr static auto LONG = OptionType::LONG;
constexpr static auto SHORT = OptionType::SHORT;
/*! Expose the OptionType enum. */
using enum OptionType;

/*! Determine whether the given word is an option argument. */
static bool isOptionArgument(const QString &wordArg, OptionType type = UNDEFINED);
static bool isOptionArgument(const QString &wordArg, OptionType type = ANY);
/*! Determine whether the given word is a long option argument. */
inline static bool isLongOption(const QString &wordArg);
/*! Determine whether the given word is a short option argument. */
Expand Down
17 changes: 7 additions & 10 deletions tom/include/tom/concerns/interactswithio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,19 @@ namespace Concerns
/*! Verbosity levels. */
enum struct Verbosity : quint8
{
/*! Quiet verbosity. */
Quiet = 0x0001,
/*! Normal verbosity (default). */
Normal = 0x0002,
/*! Verbose verbosity. */
Verbose = 0x0004,
/*! Very verbose verbosity. */
VeryVerbose = 0x0008,
/*! Debug verbosity. */
Debug = 0x0010,
};
/*! Quiet verbosity. */
constexpr static Verbosity Quiet = Verbosity::Quiet;
/*! Normal verbosity (default). */
constexpr static Verbosity Normal = Verbosity::Normal;
/*! Verbose verbosity. */
constexpr static Verbosity Verbose = Verbosity::Verbose;
/*! Very verbose verbosity. */
constexpr static Verbosity VeryVerbose = Verbosity::VeryVerbose;
/*! Debug verbosity. */
constexpr static Verbosity Debug = Verbosity::Debug;
/*! Expose the Verbosity enum. */
using enum Verbosity;

/*! Write a string as standard output. */
const InteractsWithIO &line(const QString &string, bool newline = true,
Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/commands/completecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@ bool CompleteCommand::isOptionArgument(const QString &wordArg, const OptionType
const auto isLong = wordArg.startsWith(DoubleDash);
const auto isShort = isLong ? false : wordArg.startsWith(DASH);

if (type == UNDEFINED)
// Consider both long and short option arguments
if (type == ANY)
return isLong || isShort;

if (type == LONG)
Expand Down

0 comments on commit 433c4ac

Please sign in to comment.