Commit 70e0facd authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Split PhoenixGenerator lib in a separate project

parent 947ee71e
...@@ -4,11 +4,10 @@ cmake_minimum_required(VERSION 2.8) ...@@ -4,11 +4,10 @@ cmake_minimum_required(VERSION 2.8)
add_subdirectory(cmake) add_subdirectory(cmake)
phoenix_base_project("PhoenixFileGenerator" "1.0.1" phoenix_base_project("PhoenixFileGenerator" "1.0.1"
"Tool to create Beamer presentation automatically" "Tool to generate code automatically"
"https://gitlab.in2p3.fr/CTA-LAPP/PhoenixFileGenerator") "https://gitlab.in2p3.fr/CTA-LAPP/PhoenixFileGenerator")
pull_extra_module("StringUtils" "https://gitlab.in2p3.fr/CTA-LAPP/StringUtils.git") pull_extra_module("PhoenixGenerator" "https://gitlab.in2p3.fr/CTA-LAPP/PhoenixGenerator.git")
pull_extra_module("FileParser" "https://gitlab.in2p3.fr/CTA-LAPP/FileParser.git")
pull_extra_module("OptionParser" "https://gitlab.in2p3.fr/CTA-LAPP/OptionParser.git") pull_extra_module("OptionParser" "https://gitlab.in2p3.fr/CTA-LAPP/OptionParser.git")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
......
project(Phoenix) project(Phoenix)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
add_subdirectory(PhoenixGenerator)
add_definitions(-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") add_definitions(-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_executable(phoenix_filegenerator main.cpp) add_executable(phoenix_filegenerator main.cpp)
......
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
file(GLOB phoenixGenerator_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(phoenix_generator SHARED ${phoenixGenerator_SRC})
target_link_libraries(phoenix_generator file_parser string_utils)
install(TARGETS phoenix_generator LIBRARY DESTINATION ${LIBRARY_DIRECTORY} ARCHIVE DESTINATION ${LIBRARY_DIRECTORY})
file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
install(FILES ${headers} DESTINATION include/PhoenixGenerator)
phoenix_create_find(PhoenixGenerator phoenix_generator header_generator.h "" FileParser StringUtils)
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "PClassAttribute.h"
///Constructor of class PClassAttribute
PClassAttribute::PClassAttribute(){
}
///Copy Constructor of class PClassAttribute
/** @param other : PClassAttribute we want ot copy
*/
PClassAttribute::PClassAttribute(const PClassAttribute & other){
copyPClassAttribute(other);
}
///Destructor of class PClassAttribute
PClassAttribute::~PClassAttribute(){
}
///Operator = of class PClassAttribute
/** @param other : PClassAttribute we want ot copy
* @return copied class PClassAttribute
*/
PClassAttribute & PClassAttribute::operator = (const PClassAttribute & other){
copyPClassAttribute(other);
return *this;
}
///Sets the type of the PClassAttribute
/** @param type : type of the PClassAttribute
*/
void PClassAttribute::setType(const std::string & type){
p_type = type;
}
///Sets the name of the PClassAttribute
/** @param name : name of the PClassAttribute
*/
void PClassAttribute::setName(const std::string & name){
p_name = name;
}
///Sets the isPointer of the PClassAttribute
/** @param isPointer : isPointer of the PClassAttribute
*/
void PClassAttribute::setIsPointer(bool isPointer){
p_isPointer = isPointer;
}
///Sets the isReference of the PClassAttribute
/** @param isReference : isReference of the PClassAttribute
*/
void PClassAttribute::setIsReference(bool isReference){
p_isReference = isReference;
}
///Sets the documentation of the PClassAttribute
/** @param documentation : documentation of the PClassAttribute
*/
void PClassAttribute::setDocumentation(const std::string & documentation){
p_documentation = documentation;
}
///Gets the type of the PClassAttribute
/** @return type of the PClassAttribute
*/
const std::string & PClassAttribute::getType() const{
return p_type;
}
///Gets the type of the PClassAttribute
/** @return type of the PClassAttribute
*/
std::string & PClassAttribute::getType(){
return p_type;
}
///Gets the name of the PClassAttribute
/** @return name of the PClassAttribute
*/
const std::string & PClassAttribute::getName() const{
return p_name;
}
///Gets the name of the PClassAttribute
/** @return name of the PClassAttribute
*/
std::string & PClassAttribute::getName(){
return p_name;
}
///Gets the isPointer of the PClassAttribute
/** @return isPointer of the PClassAttribute
*/
bool PClassAttribute::getIsPointer() const{
return p_isPointer;
}
///Gets the isPointer of the PClassAttribute
/** @return isPointer of the PClassAttribute
*/
bool & PClassAttribute::getIsPointer(){
return p_isPointer;
}
///Gets the isReference of the PClassAttribute
/** @return isReference of the PClassAttribute
*/
bool PClassAttribute::getIsReference() const{
return p_isReference;
}
///Gets the isReference of the PClassAttribute
/** @return isReference of the PClassAttribute
*/
bool & PClassAttribute::getIsReference(){
return p_isReference;
}
///Gets the documentation of the PClassAttribute
/** @return documentation of the PClassAttribute
*/
const std::string & PClassAttribute::getDocumentation() const{
return p_documentation;
}
///Gets the documentation of the PClassAttribute
/** @return documentation of the PClassAttribute
*/
std::string & PClassAttribute::getDocumentation(){
return p_documentation;
}
///Copy Function of class PClassAttribute
/** @param other : PClassAttribute we want ot copy
*/
void PClassAttribute::copyPClassAttribute(const PClassAttribute & other){
p_type = other.p_type;
p_name = other.p_name;
p_isPointer = other.p_isPointer;
p_isReference = other.p_isReference;
p_documentation = other.p_documentation;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __PCLASSATTRIBUTE_H__
#define __PCLASSATTRIBUTE_H__
#include <string>
///@brief Describes a class attribute
class PClassAttribute{
public:
PClassAttribute();
PClassAttribute(const PClassAttribute & other);
virtual ~PClassAttribute();
PClassAttribute & operator = (const PClassAttribute & other);
void setType(const std::string & type);
void setName(const std::string & name);
void setIsPointer(bool isPointer);
void setIsReference(bool isReference);
void setDocumentation(const std::string & documentation);
const std::string & getType() const;
std::string & getType();
const std::string & getName() const;
std::string & getName();
bool getIsPointer() const;
bool & getIsPointer();
bool getIsReference() const;
bool & getIsReference();
const std::string & getDocumentation() const;
std::string & getDocumentation();
protected:
void copyPClassAttribute(const PClassAttribute & other);
private:
///Type of the attribute
std::string p_type;
///Name of the attribute
std::string p_name;
///true if is a pointer
bool p_isPointer;
///True if it is a reference
bool p_isReference;
///Documentation string
std::string p_documentation;
};
#endif
#include <string>
///@brief Describes a class attribute
PClassAttribute{
///Type of the attribute
std::string type;
///Name of the attribute
std::string name;
///true if is a pointer
bool isPointer;
///True if it is a reference
bool isReference;
///Documentation string
std::string documentation;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "PClassConfig.h"
///Default constructeur of PClassConfig
PClassConfig::PClassConfig(){
initialisationPClassConfig();
}
///Copy constructor of PClassConfig
/** @param other : class to copy
*/
PClassConfig::PClassConfig(const PClassConfig & other){
copyPClassConfig(other);
}
///Destructeur of PClassConfig
PClassConfig::~PClassConfig(){
}
///Definition of equal operator of PClassConfig
/** @param other : class to copy
* @return copied class
*/
PClassConfig & PClassConfig::operator = (const PClassConfig & other){
copyPClassConfig(other);
return *this;
}
///Sets the class documentation
/** @param classDocumentation : class documentation
*/
void PClassConfig::setClassDocumentation(const std::string & classDocumentation){
p_classDocumentation = classDocumentation;
}
///Sets the class name
/** @param name : name of the class
*/
void PClassConfig::setName(const std::string & name){
p_name = name;
}
///Sets the list of attributes of the class
/** @param listAttribute : list of the attributes of the class
*/
void PClassConfig::setListAttribute(const std::list<PClassAttribute> & listAttribute){
p_listAttribute = listAttribute;
}
///Adds an attribute to the class
/** @param attribute : attribute to add to the class
*/
void PClassConfig::addAttribute(const PClassAttribute & attribute){
p_listAttribute.push_back(attribute);
}
///Adds a list of attributes to the class
/** @param listAttribute : list of attributes to add to the class
*/
void PClassConfig::addListAttribute(const std::list<PClassAttribute> & listAttribute){
for(std::list<PClassAttribute>::const_iterator it(listAttribute.begin()); it != listAttribute.end(); ++it){
addAttribute(*it);
}
}
///Add a parent class to the PClassConfig
/** @param parentClass : parent class we want to add in the PClassConfig
*/
void PClassConfig::addParentClass(const std::string & parentClass){
p_listParentClass.push_back(parentClass);
}
///Add a parent classes to the PClassConfig
/** @param listParentClass : list of parent classes we want to add in the PClassConfig
*/
void PClassConfig::addListParentClass(const std::list<std::string> & listParentClass){
for(std::list<std::string>::const_iterator it(listParentClass.begin()); it != listParentClass.end(); ++it){
addParentClass(*it);
}
}
///Returns the class name
/** @return class name
*/
const std::string & PClassConfig::getName() const{return p_name;}
///Returns the class name
/** @return class name
*/
std::string & PClassConfig::getName(){return p_name;}
///Returns the class documentation
/** @return class documentation
*/
const std::string & PClassConfig::getClassDocumentation() const{return p_classDocumentation;}
///Returns the class documentation
/** @return class documentation
*/
std::string & PClassConfig::getClassDocumentation(){return p_classDocumentation;}
///Returns the list of attributes of the class
/** @return list of attributes of the class
*/
const std::list<PClassAttribute> & PClassConfig::getListAttribute() const{return p_listAttribute;}
///Returns the list of attributes of the class
/** @return list of attributes of the class
*/
std::list<PClassAttribute> & PClassConfig::getListAttribute(){return p_listAttribute;}
///Returns the list of the parents of the class
/** @return list of the parents of the class
*/
const std::list<std::string> & PClassConfig::getListParentClass() const{return p_listParentClass;}
///Returns the list of the parents of the class
/** @return list of the parents of the class
*/
std::list<std::string> & PClassConfig::getListParentClass(){return p_listParentClass;}
///Copy function of PClassConfig
/** @param other : class to copy
*/
void PClassConfig::copyPClassConfig(const PClassConfig & other){
p_listAttribute = other.p_listAttribute;
p_name = other.p_name;
p_classDocumentation = other.p_classDocumentation;
p_listParentClass = other.p_listParentClass;
}
///Initialisation function of the class PClassConfig
void PClassConfig::initialisationPClassConfig(){
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __PCLASSCONFIG_H__
#define __PCLASSCONFIG_H__
#include <list>
#include "PClassAttribute.h"
///@brief Class to describe a basic class
class PClassConfig{
public:
PClassConfig();
PClassConfig(const PClassConfig & other);
virtual ~PClassConfig();
PClassConfig & operator = (const PClassConfig & other);
void setClassDocumentation(const std::string & classDocumentation);
void setName(const std::string & name);
void setListAttribute(const std::list<PClassAttribute> & listAttribute);
void addAttribute(const PClassAttribute & attribute);
void addListAttribute(const std::list<PClassAttribute> & listAttribute);
void addParentClass(const std::string & parentClass);
void addListParentClass(const std::list<std::string> & listParentClass);
const std::string & getName() const;
std::string & getName();
const std::string & getClassDocumentation() const;
std::string & getClassDocumentation();
const std::list<PClassAttribute> & getListAttribute() const;
std::list<PClassAttribute> & getListAttribute();
const std::list<std::string> & getListParentClass() const;
std::list<std::string> & getListParentClass();
protected:
void copyPClassConfig(const PClassConfig & other);
private:
void initialisationPClassConfig();
///Class documentation
std::string p_classDocumentation;
///Name of the class
std::string p_name;
///List of the attribute of the class
std::list<PClassAttribute> p_listAttribute;
///List of the parent classes of the current class
std::list<std::string> p_listParentClass;
};
#endif
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "string_utils.h"
#include "PClassGenerator.h"
#include "header_generator.h"
using namespace std;
///Constructor of PClassGenerator
PClassGenerator::PClassGenerator(){
initialisationPClassGenerator();
}
///Destructor of PClassGenerator
PClassGenerator::~PClassGenerator(){
}
///Saves both files include and sources of the class
/** @param baseFileName : base of the files names to write
* @return true on success, false otherwise
*/
bool PClassGenerator::saveFileImplDef(const std::string & baseFileName){
std::string baseToUse("");
if(baseFileName == ""){baseToUse = p_className;}
else{baseToUse = baseFileName;}
std::string includeName(baseToUse + ".h");
std::string sourceName(baseToUse + ".cpp");
if(p_useTemplate){sourceName = baseToUse + "_impl.h";}
bool b(saveFileDef(includeName, sourceName));
b &= saveFileImpl(sourceName, includeName);
return b;
}
///Saves class definition
/** @param fileNameInclude : file to write
* @param fileNameSource : file of source
* @return true on success, false otherwise
*/
bool PClassGenerator::saveFileDef(const std::string & fileNameInclude, const std::string & fileNameSource){
std::ofstream fs;
fs.open(fileNameInclude.c_str());
if(!fs.is_open()){
std::cerr << "PClassGenerator::saveFileDef : can't open file '" << fileNameInclude << "'" << std::endl;
return false;
}
licenceSave(fs);
std::string macroDef(makeMultiIncludeDefineMacro(fileNameInclude));
fs << "#ifndef " << macroDef << endl;
fs << "#define " << macroDef << endl << endl << endl;
bool b = saveClassDef(fs);
saveTemplateEndDefinition(fs, fileNameSource);
fs << endl << endl << "#endif" << endl << endl;
fs.close();
return b;
}
///Saves class implementation
/** @param fileNameSource : file to write
* @param fileNameInclude : include file name
* @return true on success, false otherwise
*/
bool PClassGenerator::saveFileImpl(const std::string & fileNameSource, const std::string & fileNameInclude){
std::ofstream fs;
fs.open(fileNameSource.c_str());
if(!fs.is_open()){
std::cerr << "PClassGenerator::saveFileImpl : can't open file '" << fileNameSource << "'" << std::endl;
return false;
}
licenceSave(fs);
saveTemplateBeginImpl(fs, fileNameInclude);
fs << endl << "#include \"" << fileNameInclude << "\"" << endl << endl;
bool b = saveClassImpl(fs);
fs << endl << endl;
saveTemplateEndImpl(fs);
fs << endl << endl;
fs.close();
return b;
}
///Saves class definition
/** @param fs : file to write
* @return true on success, false otherwise
*/
bool PClassGenerator::saveClassDef(std::ofstream & fs){
if(p_classBrief != "") fs << "///@brief " << p_classBrief << endl;
saveTemplateDefinition(fs);
fs << "class " << p_className << "{" << endl;
fs << "\tpublic:" << endl;
saveConstructorDef(fs);
saveCopyContructorDef(fs);
saveDestructorDef(fs);
saveCopyEqualOperatorDef(fs);
fs << "\tprotected:" << endl;
saveCopyFunctionDef(fs);
fs << "\tprivate:" << endl;
saveInitialisationFunctionDef(fs);
fs << "};" << endl << endl;;
return true;
}
///Saves class implementation
/** @param fs : file to write
* @return true on success, false otherwise
*/
bool PClassGenerator::saveClassImpl(std::ofstream & fs){
saveConstructorImpl(fs);
saveCopyContructorImpl(fs);
saveDestructorImpl(fs);
saveCopyEqualOperatorImpl(fs);
saveCopyFunctionImpl(fs);
saveInitialisationFunctionImpl(fs);
return true;
}
///Set the class name
/** @param className : class name
*/
void PClassGenerator::setClassName(const std::string & className){
p_className = className;
p_classNameSpace = className;
p_classTypeName = className;