mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mxlib.hpp
Go to the documentation of this file.
1 /** \file mxlib.hpp
2  * \author Jared R. Males
3  * \brief Declarations of some libarary wide utilities
4  *
5  */
6 
7 //***********************************************************************//
8 // Copyright 2015, 2016, 2017, 2018 Jared R. Males (jaredmales@gmail.com)
9 //
10 // This file is part of mxlib.
11 //
12 // mxlib is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // mxlib is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
24 //***********************************************************************//
25 
26 #ifndef mxlib_hpp
27 #define mxlib_hpp
28 
29 #include <ios>
30 
31 #include "mxlib_uncomp_version.h"
32 
33 namespace mx
34 {
35 
36 const char * mxlib_comp_current_branch();
37 
38 const char * mxlib_comp_current_sha1();
39 
40 const bool mxlib_comp_repo_modified();
41 
42 ///Dump the current git status of the library to a stream
43 /** Prints the current SHA1 hash and whether or not the library
44  * has been modified since that commit.
45  *
46  * \tparam iosT a std::ostream-like type
47  * \tparam comment a character to print at the beginning of each line. Default is '#'.
48  */
49 template<typename iosT, char comment='#'>
50 iosT & dumpGitStatus( iosT & ios /**< [in] a std::ostream-like stream. */)
51 {
52  //This causes the stream to not output a '\0' if comment = '\0'
53  char c[] = {comment, '\0'};
54 
55  ios << c << "--------------------------------------------\n";
56  ios << c << " mxlib git status \n";
57  ios << c << " headers: \n";
58  ios << c << " branch: " << MXLIB_UNCOMP_BRANCH << "\n";
59  ios << c << " SHA1: " << MXLIB_UNCOMP_CURRENT_SHA1 << "\n";
60  ios << c << " modified flag: " << std::boolalpha << (bool) MXLIB_UNCOMP_REPO_MODIFIED << "\n";
61  ios << c << " compiled: \n";
62  ios << c << " branch: " << mxlib_comp_current_branch() << "\n";
63  ios << c << " SHA1: " << mxlib_comp_current_sha1() << "\n";
64  ios << c << " modified flag: " << std::boolalpha << (bool) mxlib_comp_repo_modified() << "\n";
65  ios << c << "--------------------------------------------\n";
66 
67  return ios;
68 }
69 
70 ///Dump the git status of a repository to a stream
71 /** Prints the provided SHA1 hash and whether or not the library
72  * has been modified since that commit.
73  *
74  * \tparam iosT a std::ostream-like type
75  * \tparam comment a character to print at the beginning of each line. Default is '#'.
76  */
77 template<typename iosT, char comment='#'>
78 iosT & dumpGitStatus( iosT & ios, ///< [in] a std::ostream-like stream.
79  const std::string & repoName, ///< [in] The name of the repository
80  const std::string & branch, ///< [in] The name of the branch
81  const std::string & sha1, ///< [in] The sha1 hash for the current commit
82  const bool & modified, ///< [in] Whether or not the repository is currently modified
83  const std::string & section = "" ///< [in] [optional] Descriptive sub-section name (e.g. headers vs. compiled)
84  )
85 {
86  //This causes the stream to not output a '\0' if comment = '\0'
87  char c[] = {comment, '\0'};
88 
89  bool sect = !(section == "");
90  std::string space = " ";
91  if(sect) space += " ";
92 
93  ios << c << "--------------------------------------------\n";
94  ios << c << " " << repoName << " git status:\n";
95  if(sect) ios << c << " " << section << ":\n";
96  ios << c << space << "branch: " << branch << "\n";
97  ios << c << space << "SHA1: " << sha1 << "\n";
98  ios << c << space << "modified flag: " << std::boolalpha << modified << "\n";
99  ios << c << "--------------------------------------------\n";
100 
101  return ios;
102 }
103 
104 }//namespace mx
105 
106 #endif // mxlib_hpp
constexpr units::realT c()
The speed of light.
Definition: constants.hpp:60
The mxlib c++ namespace.
Definition: mxError.hpp:107
iosT & dumpGitStatus(iosT &ios)
Dump the current git status of the library to a stream.
Definition: mxlib.hpp:50