I use semantic versioning , and so I created the following custom type:
version.hpp
#include <string> #include <cstdlib> #include <iostream> class Version_Number{ public: //constructors Version_Number(); //<- constructs to 0.0.0 Version_Number(std::string const& version_number); //transformers void Major_Update(); void Minor_Update(); void Bug_Update(); //observers std::string str(); friend std::ostream& operator<<(std::ostream& os, const Version_Number& r); bool operator < (Version_Number const& other) const; bool operator > (Version_Number const& other) const; bool operator == (Version_Number const& other) const; bool operator != (Version_Number const& other) const; private: unsigned int a,b,c; };
version.cpp
#include <string> #include <cstdlib> #include <iostream> #include "version_number.hpp" Version_Number::Version_Number(): a(0),b(0),c(0){} Version_Number::Version_Number(std::string const& folder_name){ std::string a_str,b_str,c_str; auto it = folder_name.begin(); while (*it != '.'){ a_str+=*it; ++it; } ++it; while (*it != '.'){ b_str+=*it; ++it; } ++it; while (it != folder_name.end()){ c_str+=*it; ++it; } a = std::atoi(a_str.c_str()); b = std::atoi(b_str.c_str()); c = std::atoi(c_str.c_str()); } void Version_Number::Major_Update(){ ++a; b = 0; c = 0; return; } void Version_Number::Minor_Update(){ ++b; c = 0; return; } void Version_Number::Bug_Update(){ ++c; return; } std::string Version_Number::str(){ std::string str; str+= std::to_string(a); str+='.'; str+= std::to_string(b); str+='.'; str+= std::to_string(c); return str; } bool Version_Number::operator < (Version_Number const& other) const{ if (a > other.a){return false;} if (a < other.a){return true;} if (b > other.b){return false;} if (b < other.b){return true;} if (c > other.c){return false;} if (c < other.c){return true;} return false; } bool Version_Number::operator > (Version_Number const& other) const{ if (a < other.a){return false;} if (a > other.a){return true;} if (b < other.b){return false;} if (b > other.b){return true;} if (c < other.c){return false;} if (c > other.c){return true;} return false; } bool Version_Number::operator == (Version_Number const& other) const{ if (a == other.a){ if (b == other.b){ if (c == other.c){ return true; } } } return false; } bool Version_Number::operator != (Version_Number const& other) const{ if (a == other.a){ if (b == other.b){ if (c == other.c){ return false; } } } return true; } std::ostream& operator<<(std::ostream& os, const Version_Number& r){ os << ra << '.' << rb << '.' << rc; return os; }
source share