Commit 413c4279 authored by Brian Panneton's avatar Brian Panneton
Browse files

FIX: Cleaned up Version Suite and added the version into XdmfWriter.

parent 7560d548
#ifndef PROJECT_VERSION_HPP
#define PROJECT_VERSION_HPP
/* Version Suite Class
* Author: Brian Panneton
*/
#include <string>
#include <sstream>
/**
* @brief Version Suite to assist in adding versioning to your project
*
* A simple way to have the library contain its own version.
*/
class ProjectVersion {
public:
/**
* Create a Version class object
*
* @param name of the project
*/
ProjectVersion(std::string iProjectName, int iMajor, int iMinor) {
setProjectName(iProjectName);
setMajor(iMajor);
setMinor(iMinor);
}
/**
* Get the version string
*
* @return the Version in "ProjectName Major.Minor" string format
*/
std::string getFull() {
return getProjectName()+std::string(" ")+
getMajorStr()+std::string(".")+
getMinorStr();
}
/**
* Get the shorter version string
*
* @return the Version in "Major.Minor" string format
*/
std::string getShort() {
return getMajorStr()+std::string(".")+
getMinorStr();
}
/**
* Get the version objects project name
*
* @return the project name in string format
*/
std::string getProjectName() { return ProjectName; }
/**
* Get the Version Major
*
* @return the Version Major in string format
*/
std::string getMajorStr()
{ return IntToStr(Major); }
/**
* Get the Version Minor
*
* @return the Version Minor in string format
*/
std::string getMinorStr()
{ return IntToStr(Minor); }
/**
* Get the Version Major
*
* @return the Version Major in int format
*/
int getMajor() { return Major; }
/**
* Get the Version Minor
*
* @return the Version Minor in int format
*/
int getMinor() { return Minor; }
private:
std::string ProjectName;
int Major, Minor;
std::string IntToStr(int number) {
std::stringstream s;
s << number;
return s.str();
}
void setProjectName(std::string iProjectName)
{ ProjectName = iProjectName; }
void setMajor(int iMajor) { Major = iMajor; }
void setMinor(int iMinor) { Minor = iMinor; }
};
#endif //PROJECT_VERSION_HPP
......@@ -15,6 +15,13 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/CMake/VersionSuite)
SET(vMajor "0")
SET(vMinor "0")
# This Macro allows you to set up the Version in a one liner
MACRO(VersionCreate versionName versionMajor)
VersionMajorSet(${versionMajor})
VersionCalculate()
VersionWrite(${versionName})
ENDMACRO(VersionCreate versionName versionMajor)
# This Macro allows you to set the rewrite number
MACRO(VersionMajorSet versionMajor)
SET(vMajor ${versionMajor})
......@@ -32,11 +39,13 @@ MACRO(VersionCalculate)
ENDMACRO(VersionCalculate)
# This Macro writes your hpp file
MACRO(VersionWrite versionProjectName)
FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/${versionProjectName}Version.hpp
"/*Current Version of ${versionProjectName}*/
\#define VersionMajor ${vMajor}
\#define VersionMinor ${vMinor}
\#include \"Version.hpp\"\n"
MACRO(VersionWrite vProjectName)
FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/${vProjectName}Version.hpp
"\#ifndef ${vProjectName}_VERSION_HPP
\#define ${vProjectName}_VERSION_HPP
/* Current Version of ${vProjectName} */
\#include \"ProjectVersion.hpp\"
ProjectVersion ${vProjectName}Version = ProjectVersion(\"${vProjectName}\", ${vMajor}, ${vMinor});
\#endif\n"
)
ENDMACRO(VersionWrite)
/* Version Suite Class
* Author: Brian Panneton
*/
#include <string>
#include <sstream>
/**
* @brief Version Suite to assist in adding versioning to your project
*
* A simple way to have the library contain its own version.
*/
class Version {
public:
/**
* Create a Version class object
*
* @param name of the project
*/
Version(std::string cProjectName) {
setProjectName(cProjectName);
setMajor(VersionMajor);
setMinor(VersionMinor);
}
/**
* Get the version string
*
* @return the Version in "ProjectName Major.Minor" string format
*/
std::string getVersion() {
return getProjectName()+std::string(" ")+
getMajorStr()+std::string(".")+
getMinorStr();
}
/**
* Get the shorter version string
*
* @return the Version in "Major.Minor" string format
*/
std::string getVersionShort() {
return getMajorStr()+std::string(".")+
getMinorStr();
}
/**
* Get the version objects project name
*
* @return the project name in string format
*/
std::string getProjectName() { return ProjectName; }
/**
* Get the Version Major
*
* @return the Version Major in string format
*/
std::string getMajorStr()
{ return IntToStr(Major); }
/**
* Get the Version Minor
*
* @return the Version Minor in string format
*/
std::string getMinorStr()
{ return IntToStr(Minor); }
/**
* Get the Version Major
*
* @return the Version Major in int format
*/
int getMajor() { return Major; }
/**
* Get the Version Minor
*
* @return the Version Minor in int format
*/
int getMinor() { return Minor; }
private:
std::string ProjectName;
int Major, Minor;
std::string IntToStr(int number) {
std::stringstream s;
s << number;
return s.str();
}
void setProjectName(std::string iProjectName)
{ ProjectName = iProjectName; }
void setMajor(int iMajor) { Major = iMajor; }
void setMinor(int iMinor) { Minor = iMinor; }
};
......@@ -3,9 +3,7 @@ cmake_minimum_required(VERSION 2.6)
include(SetUpVersion)
if(VERSION_CONTROL_AUTOUPDATE)
VersionMajorSet("2")
VersionCalculate()
VersionWrite("Xdmf")
VersionCreate("Xdmf" "2")
endif(VERSION_CONTROL_AUTOUPDATE)
set(BUILD_SHARED_LIBS true)
......
/*Current Version of Xdmf*/
#define VersionMajor 2
#define VersionMinor 0
#include "Version.hpp"
#ifndef Xdmf_VERSION_HPP
#define Xdmf_VERSION_HPP
/* Current Version of Xdmf */
#include "ProjectVersion.hpp"
ProjectVersion XdmfVersion = ProjectVersion("Xdmf", 2, 0);
#endif
......@@ -10,6 +10,7 @@
#include "XdmfItem.hpp"
#include "XdmfSystemUtils.hpp"
#include "XdmfWriter.hpp"
#include "XdmfVersion.hpp"
/**
* PIMPL
......@@ -31,7 +32,7 @@ public:
mXMLFilePath(XdmfSystemUtils::getRealPath(xmlFilePath)),
mXPathCount(0),
mXPathString(""),
mVersionString("2.0")
mVersionString(XdmfVersion.getShort())
{
};
......
......@@ -2,12 +2,7 @@
#include "XdmfVersion.hpp"
int main() {
Version *v = new Version("Xdmf");
if(v->getVersion() == "")
exit(-1);
if(v->getVersionShort() == "")
exit(-1);
std::cout << v->getVersion() << std::endl;
std::cout << v->getVersionShort();
std::cout << XdmfVersion.getFull() << std::endl;
std::cout << XdmfVersion.getShort() << std::endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment