Skip to content

Commit

Permalink
Adopt stl
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szuster <[email protected]>
  • Loading branch information
Amaroq7 committed Mar 23, 2020
1 parent 471d0cf commit c4acbac
Show file tree
Hide file tree
Showing 81 changed files with 2,196 additions and 2,496 deletions.
29 changes: 14 additions & 15 deletions include/public/ICmdSystem.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 SPMod Development Team
* Copyright (C) 2018-2020 SPMod Development Team
*
* This file is part of SPMod.
*
Expand All @@ -8,13 +8,13 @@
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* SPMod is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with SPMod. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
Expand All @@ -26,7 +26,8 @@ namespace SPMod
class ICommand
{
public:
using Callback = IForward::ReturnValue (*)(IPlayer *const player, const ICommand *const cmd, void *data);
using Callback =
std::function<IForward::ReturnValue(IPlayer *const player, ICommand *const cmd, std::any data)>;

enum class Type : std::uint8_t
{
Expand All @@ -35,18 +36,18 @@ namespace SPMod
};

/**
* @brief Returns command's name.
* @brief Returns command's regex.
*
* @return Command's name.
* @return Command's regex.
*/
virtual const char *getCmd() const = 0;
virtual const std::regex &getRegex() const = 0;

/**
* @brief Returns command's info.
*
* @return Command's info.
*/
virtual const char *getInfo() const = 0;
virtual std::string_view getInfo() const = 0;

/**
* @brief Checks if player can execute the command.
Expand All @@ -55,7 +56,7 @@ namespace SPMod
*
* @return True if player has access, false otherwise.
*/
virtual bool hasAccess(IPlayer *player) const = 0;
virtual bool hasAccess(const IPlayer *player) const = 0;

/**
* @brief Returns command's access flags.
Expand All @@ -64,7 +65,6 @@ namespace SPMod
*/
virtual std::uint32_t getAccess() const = 0;

protected:
virtual ~ICommand() = default;
};

Expand All @@ -81,7 +81,7 @@ namespace SPMod
*
* @return Interface's name.
*/
const char *getName() const override
std::string_view getName() const override
{
return "ICommandMngr";
}
Expand Down Expand Up @@ -111,13 +111,12 @@ namespace SPMod
* @return Registered command.
*/
virtual ICommand *registerCommand(ICommand::Type type,
const char *cmd,
const char *info,
std::string_view cmd,
std::string_view info,
std::uint32_t flags,
ICommand::Callback cb,
void *data) = 0;
std::any data) = 0;

protected:
virtual ~ICommandMngr() = default;
};
} // namespace SPMod
31 changes: 15 additions & 16 deletions include/public/ICvarSystem.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 SPMod Development Team
* Copyright (C) 2018-2020 SPMod Development Team
*
* This file is part of SPMod.
*
Expand All @@ -8,13 +8,13 @@
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* SPMod is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* along with SPMod. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
Expand All @@ -24,7 +24,8 @@ namespace SPMod
class ICvar
{
public:
using CvarCallback = void (*)(const ICvar *const cvar, const char *old_value, const char *new_value);
using Callback =
std::function<void(const ICvar *const cvar, std::string_view old_value, std::string_view new_value)>;
/**
* Cvar flags (from engine)
*/
Expand Down Expand Up @@ -70,7 +71,7 @@ namespace SPMod
*
* @return Cvar name.
*/
virtual const char *getName() const = 0;
virtual std::string_view getName() const = 0;

/**
* @brief Returns flags of the cvar
Expand All @@ -86,7 +87,7 @@ namespace SPMod
*
* @noreturn
*/
virtual void setValue(const char *val) = 0;
virtual void setValue(std::string_view val) = 0;

/**
* @brief Set's cvar value by int
Expand All @@ -95,7 +96,7 @@ namespace SPMod
*
* @noreturn
*/
virtual void setValue(int val) = 0;
virtual void setValue(std::int32_t val) = 0;

/**
* @brief Set's cvar value by float
Expand All @@ -120,14 +121,14 @@ namespace SPMod
*
* @noreturn
*/
virtual void addCallback(CvarCallback callback) = 0;
virtual void addCallback(Callback callback) = 0;

/**
* @brief Return cvar value as integer.
*
* @return Integer cvar value
*/
virtual int asInt() const = 0;
virtual std::int32_t asInt() const = 0;

/**
* @brief Return cvar value as Float.
Expand All @@ -141,9 +142,8 @@ namespace SPMod
*
* @return String cvar value
*/
virtual const char *asString() const = 0;
virtual std::string_view asString() const = 0;

protected:
virtual ~ICvar() = default;
};

Expand All @@ -159,7 +159,7 @@ namespace SPMod
*
* @return Interface's name.
*/
const char *getName() const override
std::string_view getName() const override
{
return "ICvarMngr";
}
Expand All @@ -180,23 +180,22 @@ namespace SPMod
* @brief Registers cvar.
*
* @param name Name of the cvar.
* @param type Cvar type
* @param value_type Type of the value
* @param flags Engine flags for cvar
*
* @return Cvar pointer, nullptr if failed.
*/
virtual ICvar *registerCvar(const char *name, const char *value, ICvar::Flags flags) = 0;
virtual ICvar *registerCvar(std::string_view name, std::string_view value, ICvar::Flags flags) = 0;

/*
* @brief Find cvar.
*
* @param name Name of the cvar.
*
* @return Cvar pointer, nullptr if failed.
*/
virtual ICvar *findCvar(const char *name) = 0;
virtual ICvar *findCvar(std::string_view name) = 0;

protected:
virtual ~ICvarMngr() = default;
};
} // namespace SPMod
9 changes: 4 additions & 5 deletions include/public/IEdict.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 SPMod Development Team
* Copyright (C) 2019-2020 SPMod Development Team
*
* This file is part of SPMod.
*
Expand Down Expand Up @@ -33,7 +33,7 @@ namespace SPMod
*
* @return Interface's name.
*/
const char *getName() const override
std::string_view getName() const override
{
return "IEdict";
}
Expand All @@ -55,17 +55,16 @@ namespace SPMod
*
* @return Edict's index.
*/
virtual int getIndex() const = 0;
virtual std::uint32_t getIndex() const = 0;

virtual const char *getClassName() const = 0;
virtual std::string_view getClassName() const = 0;
virtual void getOrigin(float *origin) const = 0;
virtual void getVelocity(float *velocity) const = 0;
virtual void setVelocity(const float *velocity) = 0;
virtual float getHealth() const = 0;
virtual void setHealth(float health) = 0;
virtual void *getPrivateData() const = 0;

protected:
virtual ~IEdict() = default;
};
} // namespace SPMod
Loading

0 comments on commit c4acbac

Please sign in to comment.