repobadge/include/repoBadge.hpp

107 lines
3.3 KiB
C++

#pragma once
/*
* This file is part of the BuildIt software distribution (https://gitea.federationhq.de/byterazor/repobadge)
* Copyright (c) 2020 Dominik Meyer <dmeyer@federationhq.de>.
*
* 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, version 3.
*
* 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 <http://www.gnu.org/licenses/>.
*/
/** @file */
#include <string>
#include <sstream>
/**
* @brief namespace for all repoBadge related classes and datatypes
*/
namespace repoBadge
{
/**
* @brief some default values for colors
*/
enum class BadgeColor
{
BLUE,
BRIGHTGREEN,
GREEN,
LIGHTGREY,
ORANGE,
RED,
YELLOW,
YELLOWGREEN
};
/**
* @brief class representing a repository badge
*
* a repository badge is used to highlight the build status of a repository,
* the code coverage of the tests, or any other metric you can come up with
* for your repository.
*
* a repository badge consist of a left part used for describing the metric
* and a right part used as the value of the metric. The right part is
* highlighted by a different background color.
*/
class Badge
{
private:
/// the string used for the left part of the badge
std::string left_;
/// the string used for the right part of the badge
std::string right_;
/// the background color used for the right part of the badge
std::string color_;
public:
/**
* @brief create a badge with the default color BRIGHTGREEN
*
* @param left - the word used for the left part of the badge
* @param right - the word used for the right part of the badge
*/
Badge(const std::string &left, const std::string &right) : Badge(left,right,BadgeColor::BRIGHTGREEN) {}
/**
* @brief create a badge with the color given as a hex rgb string
*
* @param left - the word used for the left part of the badge
* @param right - the word used for the right part of the badge
* @param color - the background color used for the right part of the badge given in hex rgb (#007ec6)
*/
Badge(const std::string &left, const std::string &right,const std::string &color) : left_(left), right_(right), color_(color){};
/**
* @brief create a badge with the color given as one of the default enums
*
* @param left - the word used for the left part of the badge
* @param right - the word used for the right part of the badge
* @param color - the background color used for the right part of the badge given ad an repoBadge::BadgeColor enum
*/
Badge(const std::string &left, const std::string &right, BadgeColor color);
/**
* @brief create the svg file and return it as a string
*
* @return - the svg file
*/
std::string create();
}; //
}; // namespace repoBadge