Line data Source code
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 : #include "error/error.hpp"
34 : #include "error/exception.hpp"
35 :
36 : namespace mx
37 : {
38 :
39 : const char *mxlib_comp_current_branch();
40 :
41 : const char *mxlib_comp_current_sha1();
42 :
43 : const bool mxlib_comp_repo_modified();
44 :
45 : /// Dump the git status of a repository to a stream
46 : /** Prints the provided SHA1 hash and whether or not the library
47 : * has been modified since that commit.
48 : *
49 : * \tparam iosT a std::ostream-like type
50 : * \tparam comment a character to print at the beginning of each line. Default is '#'.
51 : */
52 : template <typename iosT, char comment = '#'>
53 1 : iosT &dumpGitStatus(
54 : iosT &ios, ///< [in] a std::ostream-like stream.
55 : const std::string &repoName, ///< [in] The name of the repository
56 : const std::string &branch, ///< [in] The name of the branch
57 : const std::string &sha1, ///< [in] The sha1 hash for the current commit
58 : const bool &modified, ///< [in] Whether or not the repository is currently modified
59 : const std::string §ion = "" ///< [in] [optional] Descriptive sub-section name (e.g. headers vs. compiled)
60 : )
61 : {
62 : // This causes the stream to not output a '\0' if comment = '\0'
63 1 : char c[] = { comment, '\0' };
64 :
65 1 : bool sect = !( section == "" );
66 1 : std::string space = " ";
67 1 : if( sect )
68 0 : space += " ";
69 :
70 1 : ios << c << "--------------------------------------------\n";
71 1 : ios << c << " " << repoName << " git status:\n";
72 1 : if( sect )
73 0 : ios << c << " " << section << ":\n";
74 1 : ios << c << space << "branch: " << branch << "\n";
75 1 : ios << c << space << "SHA1: " << sha1 << "\n";
76 1 : ios << c << space << "modified flag: " << std::boolalpha << modified << "\n";
77 1 : ios << c << "--------------------------------------------\n";
78 :
79 1 : return ios;
80 1 : }
81 :
82 : /// Dump the current git status of the mxlib library to a stream
83 : /** Prints the current SHA1 hash and whether or not the library
84 : * has been modified since that commit.
85 : *
86 : * \tparam iosT a std::ostream-like type
87 : * \tparam comment a character to print at the beginning of each line. Default is '#'.
88 : */
89 : template <typename iosT, char comment = '#'>
90 1 : iosT &dumpGitStatus( iosT &ios /**< [in] a std::ostream-like stream. */ )
91 : {
92 3 : return dumpGitStatus( ios,
93 2 : "mxlib",
94 2 : mxlib_comp_current_branch(),
95 2 : mxlib_comp_current_sha1(),
96 4 : mxlib_comp_repo_modified() );
97 : }
98 :
99 : } // namespace mx
100 :
101 : #endif // mxlib_hpp
|