libxcks  0.1.0.1
ckfactory.hpp
Go to the documentation of this file.
1 /*
2  * libxcks
3  * Copyright (C) 2022 Julien Couot
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 #ifndef INC_CKFACTORY_HPP_BD675BE3_CCFF_4396_B7D2_C9BBC2529A71
26 #define INC_CKFACTORY_HPP_BD675BE3_CCFF_4396_B7D2_C9BBC2529A71
27 
28 //---------------------------------------------------------------------------
29 #include <map>
30 
31 #include "libxcks/checksum.hpp"
32 #include "libxcks/ckvalue.hpp"
33 //---------------------------------------------------------------------------
34 
35 
36 namespace libxcks
37 {
46 class LIBXCKS_SO_EXPORT ChecksumFactory final
47 {
48  private:
49  // Represents an entry of the checksum or hash algorithms that the application
50  // knows.
51  class ChecksumEntry;
52 
54  using ChecksumEntries = std::map<ChecksumAlgoId, ChecksumEntry>;
55 
56  static ChecksumEntries checksumAlgorithms;
57 
59  ChecksumFactory() {}
60 
61  public:
63  ChecksumFactory(const ChecksumFactory&) = delete;
64 
67 
68  // Initializes the static members of the class.
69  static void initialise();
70 
71  // Cleans-up the static members of the class.
72  static void cleanUp();
73 
74  // Gives a pointer on a new instance of the specified checksum or hash identifier.
75  static Checksum* getNewInstance(const ChecksumAlgoId id);
76 
77  // Gives a pointer on a new instance of the specified checksum or hash name.
78  static Checksum* getNewInstance(const std::string& name, const bool lookInAltNames = true);
79 
80  // Gives a null value of the specified checksum or hash identifier.
81  static ChecksumValue getNullValue(const ChecksumAlgoId id);
82 
83  // Gives a null value of the specified checksum or hash name.
84  static ChecksumValue getNullValue(const std::string& name, const bool lookInAltNames = true);
85 
86  // Gets the size in bytes of the specified checksum or hash identifier.
87  static size_t getSize(const ChecksumAlgoId id);
88 
89  // Gets the size in bytes of the specified checksum or hash name.
90  static size_t getSize(const std::string& name, const bool lookInAltNames = true);
91 
92  // Returns true if the given identifier of the checksum or hash algorithm exists.
93  static bool exists(const ChecksumAlgoId id);
94 
95  // Returns true if the given name of the checksum or hash algorithm exists.
96  static bool exists(const std::string& name, const bool lookInAltNames = true);
97 
98  // Returns true if the given name of the checksum or hash algorithm exists.
99  static bool existsNoCase(const std::string& name, const bool lookInAltNames = true);
100 
101  // Returns all the identifiers of the available checksum or hash algorithms.
102  static ArrayChecksumAlgoId getAlgorithmsIds();
103 
104  // Returns all the names of the available checksum or hash algorithms.
105  static ArrayString getAlgorithmsNames();
106 
107  // Returns the number of available checksum or hash algorithms.
108  static int getAlgorithmsCount();
109 
110  // Gets the identifier of a checksum or hash algorithm from its name.
111  static bool getAlgorithmId(ChecksumAlgoId& id, const std::string& name, const bool lookInAltNames = true);
112 
113  // Gets the identifier of a checksum or hash algorithm from its name.
114  static bool getAlgorithmIdNoCase(ChecksumAlgoId& id, const std::string& name, const bool lookInAltNames = true);
115 
116  // Gets the name of a checksum or hash algorithm from its identifier.
117  static bool getAlgorithmName(std::string& name, const ChecksumAlgoId id);
118 
119  // Gets the name of a checksum or hash algorithm from one of its alternatives names.
120  static bool getAlgorithmName(std::string& name, const std::string& altName);
121 
122  // Gets the alternatives names of a checksum or hash algorithm from its identifier.
123  static bool getAlgorithmAltNames(ArrayString& altNames, const ChecksumAlgoId id, const bool giveName = false);
124 
125  // Gets the alternatives names of a checksum or hash algorithm from its name or one of its alternative names.
126  static bool getAlgorithmAltNames(ArrayString& altNames, const std::string& name, const bool nameCouldBeAlt = true, const bool giveName = false);
127 
128  // Returns the description of a checksum or hash algorithm from its identifier.
129  static std::string getAlgorithmDescription(const ChecksumAlgoId id);
130 
131  // Returns the description of a checksum or hash algorithm from its name.
132  static std::string getAlgorithmDescription(const std::string& name, const bool lookInAltNames = true);
133 };
134 //---------------------------------------------------------------------------
135 } // namespace libxcks
136 //---------------------------------------------------------------------------
137 
138 #endif // INC_CKFACTORY_HPP_BD675BE3_CCFF_4396_B7D2_C9BBC2529A71
Interface for classes that compute checksums.
Stores the value of a checksum.
Represents an entry of the checksum or hash algorithms that the application knows.
Definition: ckfactory.cpp:73
Generates new instances of the subclasses of the Checksum class that the application knows.
Definition: ckfactory.hpp:47
ChecksumFactory & operator=(const ChecksumFactory &)=delete
Deleted assignment operator.
ChecksumFactory(const ChecksumFactory &)=delete
Deleted copy constructor.
Stores the value of a checksum.
Definition: ckvalue.hpp:45
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
std::vector< ChecksumAlgoId > ArrayChecksumAlgoId
Array of ids of algorithms of checksums.
Definition: types.hpp:92
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65
std::vector< std::string > ArrayString
Array of strings.
Definition: types.hpp:44