Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #140 from DHBW-FN/develop
Browse files Browse the repository at this point in the history
Release 1.1
  • Loading branch information
TobiasGoetz committed Jul 24, 2022
2 parents 6f0f5fc + ef212f6 commit 16531b9
Show file tree
Hide file tree
Showing 32 changed files with 1,580 additions and 343 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ add_executable(

file(GLOB Source_Files2 src2/*.cpp)
add_executable(
COptionParser
ExampleProgram
${Source_Files2}
)



find_package (Boost REQUIRED)
find_package (Boost COMPONENTS log log_setup REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(CodeGenerator ${Boost_LIBRARIES})
Expand Down
2 changes: 1 addition & 1 deletion config-file
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ./src
INPUT = ./src, ./include

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
33 changes: 0 additions & 33 deletions example/Example.xml

This file was deleted.

62 changes: 62 additions & 0 deletions include/CodeGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Editors: Tobias Goetz
*/

#ifndef PROGRAMMING_C_CODEGENERATOR_H
#define PROGRAMMING_C_CODEGENERATOR_H

#include <string>

/**
* @brief Class for the CodeGenerator
*/
class CodeGenerator {
private:
/**
* @brief String containing path to the file
*/
std::string filePath;

/**
* @brief Output directory
*/
std::string outputDir;

public:
/**
* @brief Constructor
*/
CodeGenerator() = default;

/**
* @brief Get the path to the file
* @return
*/
std::string getFilePath();

/**
* Get the output directory
* @return the out directory as string
*/
std::string getOutputDir();

/**
* @brief Set the path to the file
* @param filename
*/
void setFilePath(const std::string &filename);

/**
* @brief Set the output directory
* @param dir
*/
void setOutputDir(const std::string &dir);

/**
* @brief Runs the CodeGenerator
*/
void run();
};


#endif //PROGRAMMING_C_CODEGENERATOR_H
110 changes: 110 additions & 0 deletions include/HelpText.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Editors: Sebastian Wolf, Tobias Goetz
*/

#ifndef CODEGENERATOR_HELPTEXT_H
#define CODEGENERATOR_HELPTEXT_H

#include "Justify.h"
#include "models/GetOptSetup.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
* @brief Class for the HelpText parsing
*/
class HelpText
{
public:
/**
* @brief Constructor for the HelpText
*/
explicit HelpText(GetOptSetup *getOptSetup);
/**
* @brief Destructor for the HelpText
*/
~HelpText();

/**
* @brief add function wrapper and call parse methods
* @return getHelp() Function with message as string
*/
string parseHelpMessage();

private:
/**
* @brief concatenate the description strings to one string
* @brief and add to printHelpText
*/
void parseDescription();

/**
* @brief concatenate usage strings to one string
* @brief and add to printHelpText
* @return all usage strings as a string with line break.
*/
void parseUsage();

/**
* @brief concatenate the author information to one string
* @brief and add to printHelpText
*/
void parseAuthor();

/**
* @brief concatenate the options to one string
* @brief and add to printHelpText
* call the getMaxParamLength() Method. Get concatenated params
* by calling concatParams function with i as iterator.
* write strings to buffer with a spacing using set()
* calculate a new signPerLine to space out the
* option description accordingly to the length
* of param and the shift.
* calculate a new shift for every line of the description
* that is pushed to the next line because of signPerLine,
* in order to shift the line to the right, matching the above.
* Justify the description text. Write justified text to
* class variable.
*/
void parseOption();

/**
* @brief concatenate short opt and long opt to one string
* different checks if shortOpt and LongOpt are empty
* to concatenate the right signs to the string
* @param i iteration counter to determine which option is parsed
* @return concatenated opts as string
*/
vector<string> concatParams(const vector<Option>& sortedOpts);
/**
* @brief printHelp Text
* stores the string for the printHelp method.
*/
string printHelpText;
/**
* @brief Length of longest Parameter
* Stores the length of the longest
* parameter in options.
*/
int maxOptionParamLength = 0;
/**
* @brief shift
* extra shift / space can be defined
* for the space between parameters
* and description in options.
*/
const int shift = 5;
/**
* @brief Justify object
*/
Justify justify;
/**
* @brief GetOptSetup object
*/
GetOptSetup *getOptSetup;
};

#endif //CODEGENERATOR_HELPTEXT_H
80 changes: 80 additions & 0 deletions include/Justify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Editors: Sebastian Wolf
*/

#ifndef CODEGENERATOR_JUSTIFY_H
#define CODEGENERATOR_JUSTIFY_H
#include "bits/stdc++.h"
#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>

using namespace std;
using namespace boost;

/**
* @brief Class to justify a string
* Custom Justify class according to https://www.geeksforgeeks.org/justify-the-given-text-based-on-the-given-width-of-each-line/
*/
class Justify
{
private:
/**
* @brief Function to join the words with spaces spread evenly
* @param words vector with separated words
* @param start current line start
* @param end iterator
* @param num_spaces
* @param isOption check if its an options string
* @param curr_line current line string is in
* @param optionShift shift that needs to be added to aline lines
* @return justified text
*/
static string JoinALineWithSpace(
vector<string>& words,
int start, int end,
int num_spaces,
bool isOption,
int curr_line,
int optionShift);
/**
* @brief Function that justify the words of sentence of length of line L
* @param words vector with separated words
* @param L length of sign per line
* @param isOption check if its an options string
* @param optionShift shift that needs to be added to aline lines
* @return whole justified string
*/
static vector<string> JustifyText(
vector<string>& words,
int L,
bool isOption,
int optionShift);
/**
* @brief separates a string in single words
* @param str string to parse
* @return vector with splitted words
*/
static vector<string> splitWords(const string& str);

/**
* @brief Function to return justified text
* @param result vector with justified strings
* @return justified text in as a string
*/
static string returnJustifiedText(vector<string>& result);

public:
/**
* @brief function to call the justification
* @param str string to justify
* @param L length of sign per line
* @param isOption check if its an options string
* @param optionShift shift that needs to be added to aline lines
* @return justified text as a string
*/
string justifyTheText(const string& str, int L, bool isOption, int optionShift);
};


#endif //CODEGENERATOR_JUSTIFY_H
66 changes: 66 additions & 0 deletions include/Logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Editors: Tobias Goetz, Sebastian Wolf
*/

#ifndef LOG_LOGGER_H
#define LOG_LOGGER_H
#pragma once

#include <boost/log/trivial.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/attributes/mutable_constant.hpp>
#include <boost/log/utility/manipulators/add_value.hpp>
#include <string>

BOOST_LOG_GLOBAL_LOGGER(sysLogger,
boost::log::sources::severity_channel_logger_mt<boost::log::trivial::severity_level>);
BOOST_LOG_GLOBAL_LOGGER(dataLogger,
boost::log::sources::severity_channel_logger_mt<boost::log::trivial::severity_level>);

/**
* @brief Custom logger class.
* Custom logger according to https://objectcomputing.com/resources/publications/sett/may-2016-boostlog-library
*/
class Logger {
public:
/// Init with default trivial logging
static void init();

/// @param configFileName config ini file that contains boost logging properties.
/// If configFileName.empty() then default initialization.
static void initFromConfig(const std::string& configFileName);

/// Disable logging
static void disable();

/// Add a file sink for LOG_DATA_* for >= INFO.
/// This file sink will be used along with any configured via Config in init().
static void addDataFileLog(const std::string& logFileName);
};

#define LOG_LOG_LOCATION(LOGGER, LEVEL, ARG) \
BOOST_LOG_SEV(LOGGER, boost::log::trivial::LEVEL) \
<< boost::log::add_value("Line", __LINE__) \
<< boost::log::add_value("File", __FILE__) \
<< boost::log::add_value("Function", __FUNCTION__) << ARG;

/// System Log macros.
/// TRACE < DEBUG < INFO < WARN < ERROR < FATAL
#define LOG_TRACE(ARG) LOG_LOG_LOCATION(sysLogger::get(), trace, ARG);
#define LOG_DEBUG(ARG) LOG_LOG_LOCATION(sysLogger::get(), debug, ARG);
#define LOG_INFO(ARG) LOG_LOG_LOCATION(sysLogger::get(), info, ARG);
#define LOG_WARN(ARG) LOG_LOG_LOCATION(sysLogger::get(), warning, ARG);
#define LOG_ERROR(ARG) LOG_LOG_LOCATION(sysLogger::get(), error, ARG);
#define LOG_FATAL(ARG) LOG_LOG_LOCATION(sysLogger::get(), fatal, ARG);

/// Data Log macros. Does not include LINE, FILE, FUNCTION.
/// TRACE < DEBUG < INFO < WARN < ERROR < FATAL
#define LOG_DATA_TRACE(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::trace) << ARG
#define LOG_DATA_DEBUG(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::debug) << ARG
#define LOG_DATA_INFO(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::info) << ARG
#define LOG_DATA_WARN(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::warning) << ARG
#define LOG_DATA_ERROR(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::error) << ARG
#define LOG_DATA_FATAL(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::fatal) << ARG

#endif /* LOG_LOGGER_H */
Loading

0 comments on commit 16531b9

Please sign in to comment.