libxcks  0.1.0.1
ckvalue.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 
24 #ifndef INC_CKVALUE_HPP_FD0D3DA3_A3D6_4C78_BC24_3ED4A5CD585E
25 #define INC_CKVALUE_HPP_FD0D3DA3_A3D6_4C78_BC24_3ED4A5CD585E
26 
27 //---------------------------------------------------------------------------
28 // #include <string> // already included in "libxcks/checksum.hpp"
29 // #include <vector> // already included in "libxcks/types.hpp"
30 
31 #include "libxcks/export.hpp"
32 #include "libxcks/checksum.hpp"
33 #include "libxcks/types.hpp"
34 //---------------------------------------------------------------------------
35 
36 
37 namespace libxcks
38 {
44 class LIBXCKS_SO_EXPORT ChecksumValue
45 {
46  protected:
47  uint8_t* value;
48  size_t valueSize;
50 
51  // Clones the source instance in this instance.
52  void clone(const ChecksumValue& source);
53 
54  public:
55  // Constructor.
56  ChecksumValue();
57 
58  // Constructor with a checksum's value.
59  ChecksumValue(const uint8_t* value, const size_t size, const ChecksumAlgoId type);
60 
61  // Constructor with a checksum's value.
62  ChecksumValue(const std::string& strValue, const ChecksumAlgoId type);
63 
64  // Constructor from a checksum's value.
65  ChecksumValue(const Checksum& checksum);
66 
67  // Copy constructor.
68  ChecksumValue(const ChecksumValue& source);
69 
70  // Move constructor.
72 
73  // Assignment operator.
74  ChecksumValue& operator=(const ChecksumValue& source);
75 
76  // Move assignment operator.
77  ChecksumValue& operator=(ChecksumValue&& rhs);
78 
79  // Destructor.
80  virtual ~ChecksumValue();
81 
82  // Tests if two checksum's values are equals.
83  bool operator==(const ChecksumValue& cmp) const;
84 
85  // Tests if two checksum's values are different.
86  bool operator!=(const ChecksumValue& cmp) const;
87 
88  // Compares this value with the value of another checksum.
89  int compare(const ChecksumValue& cmp) const;
90 
91  // Gets the value of the checksum.
92  const uint8_t* getValue() const;
93 
94  // Gets the value of the checksum.
95  bool getValue(uint8_t* value, const size_t size) const;
96 
97  // Sets the value of the checksum.
98  void setValue(const uint8_t* value, const size_t size, const ChecksumAlgoId type);
99 
100  // Sets the value of the checksum.
101  void setValue(const std::string& strValue, const ChecksumAlgoId type);
102 
103  // Gets the size of the checksum's value.
104  size_t getSize() const;
105 
106  // Gets the type of the checksum.
107  ChecksumAlgoId getType() const;
108 };
109 //---------------------------------------------------------------------------
110 
111 
113 using ArrayChecksumValue = std::vector<ChecksumValue>;
114 
115 
116 //###########################################################################
117 // Helper functions
118 //###########################################################################
119 
120 // Checks if the array as a value of the given type.
121 bool LIBXCKS_SO_EXPORT hasChecksumValueWithAlgoId(const ArrayChecksumValue& ckvalues, const ChecksumAlgoId type);
122 //---------------------------------------------------------------------------
123 
124 // Gets a set of null checksums' values from a set of checksums ids.
125 void LIBXCKS_SO_EXPORT getNullValues(ArrayChecksumValue& values, const ArrayChecksumAlgoId& ids);
126 //---------------------------------------------------------------------------
127 
128 } // namespace libxcks
129 //---------------------------------------------------------------------------
130 
131 #endif // INC_CKVALUE_HPP_FD0D3DA3_A3D6_4C78_BC24_3ED4A5CD585E
Interface for classes that compute checksums.
void LIBXCKS_SO_EXPORT getNullValues(ArrayChecksumValue &values, const ArrayChecksumAlgoId &ids)
Gets an array of null checksums' values from an array of checksums ids.
Definition: ckvalue.cpp:482
std::vector< ChecksumValue > ArrayChecksumValue
Array of values of checksum.
Definition: ckvalue.hpp:113
bool LIBXCKS_SO_EXPORT hasChecksumValueWithAlgoId(const ArrayChecksumValue &ckvalues, const ChecksumAlgoId type)
Checks if the array as a value of the given type.
Definition: ckvalue.cpp:456
Stores the value of a checksum.
Definition: ckvalue.hpp:45
ChecksumAlgoId type
Type of the checksum.
Definition: ckvalue.hpp:49
size_t valueSize
Size of the checksum's value.
Definition: ckvalue.hpp:48
uint8_t * value
Value of the checksum.
Definition: ckvalue.hpp:47
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
OS dependent exports defines.
Common types for libxcks.
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