Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) About

 

STLQt CreatorWindows

 

About is a class to display information about a program.

Technical facts

 

 

 

 

 

 

./CppAbout/CppAbout.pri

 

INCLUDEPATH += \
    ../../Classes/CppAbout

SOURCES += \
    ../../Classes/CppAbout/about.cpp

HEADERS  += \
    ../../Classes/CppAbout/about.h

OTHER_FILES += \
    ../../Classes/CppAbout/Licence.txt

 

 

 

 

 

./CppAbout/about.h

 

//---------------------------------------------------------------------------
/*
About, class for containing information about a program
Copyright (C) 2010-2015 Richel Bilderbeek

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, either version 3 of the License, or
(at your option) any later version.

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/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppAbout.htm
//---------------------------------------------------------------------------
#ifndef RIBI_ABOUT_H
#define RIBI_ABOUT_H

#include <iosfwd>
#include <string>
#include <vector>

namespace ribi {

///About is a class to contain 'about' information
struct About
{
  explicit About(
    const std::string author,
    const std::string file_title,
    const std::string file_description,
    const std::string programmed_on,
    const std::string years,
    const std::string url,
    const std::string version,
    const std::vector<std::string>& version_history
  ) noexcept;

  ///Add a library name and version
  void AddLibrary(const std::string& s) noexcept;

  ///Create the 'about' text
  std::vector<std::string> CreateAboutText() const noexcept;

  ///Create a version history
  std::vector<std::string> CreateVersionHistory() const noexcept;

  ///Create a text with all libraries used
  std::vector<std::string> CreateLibrariesUsedText() const noexcept;

  ///CreateLicence creates a GPL 3.0 licence.
  std::vector<std::string> CreateLicenceText() const noexcept;

  ///Obtain the version of this About class itself
  static std::string GetAboutVersion() noexcept;

  ///Obtain the version history of this About class itself
  static std::vector<std::string> GetAboutVersionHistory() noexcept;

  ///Get the author of this class
  const std::string& GetAuthor() const noexcept { return m_author; }

  ///GetBoostVersion returns the version of the current Boost library.
  ///From http://www.richelbilderbeek.nl/CppGetBoostVersion.htm
  static std::string GetBoostVersion() noexcept;

  ///Get the author of my classes
  static std::string GetDefaultAuthor() noexcept { return "Richel Bilderbeek"; }

  ///Get the file/class/program its description
  const std::string& GetFileDescription() const noexcept { return m_file_description; }

  ///Get the file/class/program its title
  const std::string& GetFileTitle() const noexcept { return m_file_title; }

  ///Get the date this class has been programmed on
  const std::string& GetProgrammedAt() const noexcept { return m_programmed_on; }

  ///GetQtCreatorVersion returns the version number of the Qt Creator currently installed.
  ///From http://www.richelbilderbeek.nl/CppGetQtCreatorVersion.htm
  static std::string GetQtCreatorVersion() noexcept;

  ///GetStlVersion returns the version number of the GCC STL currently installed.
  ///From http://www.richelbilderbeek.nl/CppGetStlVersion.htm
  static std::string GetStlVersion() noexcept;

  ///Get the URL this class can be downloaded from
  const std::string& GetUrl() const noexcept { return m_url; }

  ///Obtain the years this class has been worked on
  const std::string& GetYears() const noexcept { return m_years; }

  ///Obtain the version of this class
  const std::string& GetVersion() const noexcept { return m_version; }

  private:

  ///The author of this class
  const std::string m_author;

  ///The title or name of this class
  const std::string m_file_title;

  ///The description of this class
  const std::string m_file_description;

  ///The libraries and/or classes used by this class
  std::vector<std::string> m_libraries;

  ///The date this class was programmed
  const std::string m_programmed_on;

  ///The years this class has been worked on
  const std::string m_years;

  ///The URL this class can be downloaded from
  const std::string m_url;

  ///The version of this class
  const std::string m_version;

  ///The version history of this class
  const std::vector<std::string> m_version_history;

};

std::ostream& operator<<(std::ostream& os,const About& a) noexcept;

} //~namespace ribi

#endif // RIBI_ABOUT_H

 

 

 

 

 

./CppAbout/about.cpp

 

//---------------------------------------------------------------------------
/*
About, class for containing information about a program
Copyright (C) 2010-2015 Richel Bilderbeek

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, either version 3 of the License, or
(at your option) any later version.

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/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppAbout.htm
//---------------------------------------------------------------------------
#include "about.h"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <iterator>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/lexical_cast.hpp>
#include <boost/version.hpp>

//#include "trace.h"
#pragma GCC diagnostic pop

ribi::About::About(
    const std::string author,
    const std::string file_title,
    const std::string file_description,
    const std::string programmed_on,
    const std::string years,
    const std::string url,
    const std::string version,
    const std::vector<std::string>& version_history) noexcept
  : m_author{author},
    m_file_title{file_title},
    m_file_description{file_description},
    m_libraries{},
    m_programmed_on{programmed_on},
    m_years{years},
    m_url{url},
    m_version{version},
    m_version_history{version_history}
{
  AddLibrary(
    "About version: "
    + GetAboutVersion());
  AddLibrary(
    "Boost version: "
    + GetBoostVersion());
  AddLibrary(
    "STL version: "
    + GetStlVersion()
    + " (GNU ISO C++ library)");
}

void ribi::About::AddLibrary(const std::string& s) noexcept
{
  m_libraries.push_back(s);
  std::sort(m_libraries.begin(),m_libraries.end());
}

std::vector<std::string> ribi::About::CreateAboutText() const noexcept
{
  const std::vector<std::string> v
  {
    m_file_title + ", version " + m_version,
    "Copyright (C) " + m_years + " " + m_author,
    "Programmed on " + m_programmed_on,
    "by " + m_author,
    "",
    m_file_title + " can be downloaded from " + m_url,
    "Licenced under GPL 3.0"
  };
  return v;
}

std::vector<std::string> ribi::About::CreateLibrariesUsedText() const noexcept
{
  std::vector<std::string> v;
  v.push_back("Libraries and classes used: ");
  for(const std::string& s: m_libraries)
  {
    v.push_back(" * " + s);
  }
  return v;
}

std::vector<std::string> ribi::About::CreateLicenceText() const noexcept
{
  std::vector<std::string> v{
    m_file_title + ", " + m_file_description,
    "Copyright (C) " + m_years + " " + m_author,
    "",
    "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, either version 3 of the License, or",
    "(at your option) any later version.",
    "",
    "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/>."
  };
  return v;
}

std::vector<std::string> ribi::About::CreateVersionHistory() const noexcept
{
  std::vector<std::string> v;
  v.push_back("Version history:");
  v.push_back(" * YYYY-MM-DD: version X.Y: [description]");
  for(const std::string& s: m_version_history)
  {
    v.push_back(" * " + s);
  }
  return v;
}

std::string ribi::About::GetAboutVersion() noexcept
{
  return "1.7";
}

std::vector<std::string> ribi::About::GetAboutVersionHistory() noexcept
{
  return {
    "2011-01-07: version 1.0: initial version",
    "2011-01-11: version 1.1: added simple getters",
    "2011-09-12: version 1.2: added operator<<",
    "2012-01-08: version 1.3: fixed grammatical error",
    "2012-01-26: version 1.4: removed BOOST_FOREACH",
    "2013-04-29: version 1.5: added #ifdefs for GCC 4.4.0"
    "2013-09-05: version 1.6: transition to namespace ribi"
    "2013-09-16: version 1.7: noexcept added"
  };
}

std::string ribi::About::GetBoostVersion() noexcept
{
  std::string s = BOOST_LIB_VERSION;
  std::replace(s.begin(),s.end(),'_','.');
  return s;
}

std::string ribi::About::GetStlVersion() noexcept
{
  return boost::lexical_cast<std::string>(__VERSION__);
}

std::ostream& ribi::operator<<(std::ostream& os,const About& a) noexcept
{
  {
    const std::vector<std::string> v{a.CreateAboutText()};
    std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(os,"\n"));
  }
  os
    << '\n';
  {
    std::vector<std::string> v{a.CreateLibrariesUsedText()};
    std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(os,"\n"));
  }
  os
    << '\n';
  {
    std::vector<std::string> v{a.CreateVersionHistory()};
    std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(os,"\n"));
  }
  os
    << '\n'
    << "Licence:\n";
  {
    std::vector<std::string> v{a.CreateLicenceText()};
    std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(os,"\n"));
  }
  os
    << '\n'
    << "Source code built on "
    << __DATE__
    << " "
    << __TIME__
    << '\n'
  #ifdef NDEBUG
    << "Release version"
  #else
    << "Debug version"
  #endif
    << '\n';
  return os;
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml