redmine-api-cpp/include/Redmine/Object.hpp

87 lines
2.8 KiB
C++

#pragma once
/*
* Copyright (C) 2024 Dominik Meyer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 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,
* 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/>.
*/
#include "nlohmann/json_fwd.hpp"
#include <nlohmann/json.hpp>
/**
* @brief The main namespace of this library for Redmine related datatypes, classes, and functions
*
*/
namespace Redmine
{
/**
* @brief interface class for all redmine objects
*
* All redmine objects are expected to use a json object as their main
* data store. This supports easy working with the json base api calls.
*
*/
class Object
{
protected:
/**
* @brief verifies the validity of the provided json data
*
* This method has to check each value within the json data
* if it is valid for the object. It also has to enforce
* mandatory attributes.
*
* The method should throw exceptions if a non recoverable
* problem is found!
*
*/
virtual void _verify(const nlohmann::json &data) = 0;
void _baseVerify(const nlohmann::json &data, const std::string &objectName);
public:
/**
* @brief set the internal data of the object
*
* This method has to set all valued of the object even if some already have been
* set but are missing in the new data.
*
* It is *expected* that you reset all old data
*
* @param data - the json data holding the objects new information
*/
virtual void set(const nlohmann::json &data) = 0;
/**
* @brief returns the currently set data of the object as a json object
*
* @return nlohmann::json - the json object holding all object information
*/
virtual nlohmann::json get() const = 0;
/**
* @brief return a string representation of the object
*
* @return std::string
*/
virtual std::string to_string() const = 0;
}; // class Object
}; // namespace Redmine