1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU Lesser General Public License as published
7 //  by the Free Software Foundation; either version 3.0 of the License, or
8 //  any later version.
9 //
10 //  The GPSTk is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with GPSTk; if not, write to the Free Software Foundation,
17 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 //  This software was developed by Applied Research Laboratories at the
20 //  University of Texas at Austin.
21 //  Copyright 2004-2020, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 //  This software was developed by Applied Research Laboratories at the
28 //  University of Texas at Austin, under contract to an agency or agencies
29 //  within the U.S. Department of Defense. The U.S. Government retains all
30 //  rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 //  Pursuant to DoD Directive 523024
33 //
34 //  DISTRIBUTION STATEMENT A: This software has been approved for public
35 //                            release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 /**
40  * @file HexDumpDataConfig.hpp
41  * Define the configuration class used for the hexDumpData function.
42  */
43 
44 #ifndef GPSTK_HEXDUMPDATACONFIG_HPP
45 #define GPSTK_HEXDUMPDATACONFIG_HPP
46 
47 namespace gpstk
48 {
49    namespace StringUtils
50    {
51          // All the functionality here is inlined since they are
52          // farily small functions.
53 
54          /// @ingroup stringutilsgroup
55          //@{
56 
57          /// Class for configuring the appearance of hexDumpData() output
58       class HexDumpDataConfig
59       {
60       public:
61             /// Initialize to some sensible defaults.
62          HexDumpDataConfig();
63             /** Set most fields in a traditional manner, where
64              * separators are a specified number of space
65              * characters.
66              * @see data member documentation for an explanation of arguments.
67              */
68          HexDumpDataConfig(bool ashowIndex, bool ahexIndex, bool aupperHex,
69                            unsigned aidxDigits, unsigned aindexWS,
70                            unsigned agroupBy, unsigned agroupWS,
71                            unsigned agroup2By, unsigned agroup2WS,
72                            unsigned abytesPerLine, bool ashowText,
73                            char aseparator, unsigned atextWS,
74                            bool aShowBaseData = false,
75                            bool aShowBaseIndex = false);
76             /** Set fields using explicit strings for the separators.
77              * @see data member documentation for an explanation of arguments.
78              */
79          HexDumpDataConfig(bool ashowIndex, bool ahexIndex, bool aupperHex,
80                            unsigned aidxDigits, const std::string& aindexSep,
81                            unsigned agroupBy, const std::string& agroupSep,
82                            unsigned agroup2By, const std::string& agroup2Sep,
83                            unsigned abytesPerLine, bool ashowText,
84                            char aseparator, const std::string& atextSep,
85                            bool aShowBaseData, bool aShowBaseIndex,
86                            const std::string& adataEndSep,
87                            const std::string& adataFinal);
88             /** Set fields using explicit strings for the separators.
89              * @see data member documentation for an explanation of arguments.
90              */
91          HexDumpDataConfig(bool ashowIndex, bool ahexIndex, bool aupperHex,
92                            unsigned aidxDigits, const std::string& aindexSep,
93                            unsigned agroupBy, const std::string& agroupSep,
94                            unsigned agroup2By, const std::string& agroup2Sep,
95                            unsigned abytesPerLine, bool ashowText,
96                            const std::string& apreText,
97                            const std::string& apostText,
98                            bool aShowBaseData, bool aShowBaseIndex,
99                            const std::string& adataEndSep,
100                            const std::string& adataFinal,
101                            const std::string& aprefix);
102             /** Return the number of bytes on a line of hexDumpData
103              * output without the ASCII representation length.  This
104              * is used to line up the ASCII dump.
105              * @param[in] indent The length of the "tag" argument to
106              *   hexDumpData.
107              * @param[in] bytesOnLine The number of bytes on the line
108              *   of output (which may be different from bytesPerLine
109              *   when this function is used for the last line of
110              *   output).
111              * @param[in] lastLine If true, the length of dataFinal
112              *   will be added, otherwise the length of dataEndSep
113              *   will be added. */
114          unsigned computeLineSize(unsigned bytesOnLine,
115                                   bool lastLine) const;
116             /// Get the index radix ID
117          std::string baseIndex() const;
118             /// Get the data radix ID
119          std::string baseData() const;
120 
121          bool showIndex;        ///< display index into string on each line.
122          bool hexIndex;         ///< if true, use hex index numbers (else decimal).
123          bool upperHex;         ///< if true, use upper-case hex digits.
124          unsigned idxDigits;    ///< number of positions to use for index.
125          std::string indexSep;  ///< text between index and data.
126          unsigned groupBy;      ///< bytes of data to show between spaces.
127          std::string groupSep;  ///< text put between groups of hex data.
128          std::string group2Sep; ///< text put between 2nd layer groups.
129          std::string prefix;    ///< text to put at the start of each line.
130          std::string dataEndSep;///< text to put after last data on a line.
131          std::string dataFinal; ///< text to put after last of data.
132          std::string preText;   ///< text put between hex and ASCII.
133          std::string postText;  ///< text to put after ASCII.
134          bool showBaseData;     ///< Show number base indicator for data.
135          bool showBaseIndex;    ///< Show number base indicator for indices.
136             /** If true, show text of message (unprintable characters
137              * become '.'. */
138          bool showText;
139             /** Number of groups to show per 2nd layer group (0=none,
140              * must be multiple of groupBy). */
141          unsigned group2By;
142             /** Number of bytes to display on a line of output (must
143              * be evenly divisible by both groupBy and group2By). */
144          unsigned bytesPerLine;
145       }; // class HexDumpDataConfig
146 
147          //@}
148 
149    } // namespace StringUtils
150 } // namespace gpstk
151 
152 #endif // GPSTK_HEXDUMPDATACONFIG_HPP
153