Skip to content

Commit aaf51b4

Browse files
committed
Marked most methods of the ZSwapObject class as const.
1 parent 48b912a commit aaf51b4

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

src/lib/zswapobject/zswapobject.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414

1515
#include "zswapobject/zswapobject.hpp"
1616

17-
bool ZSwapObject::CheckPercent(const std::string& Value)
17+
bool ZSwapObject::CheckPercent(const std::string& Value) const
1818
{
1919
if (Value.empty()) return true;
2020
const int ValueInt = std::stoi(Value);
2121
return (ValueInt < 0) || (ValueInt > 100);
2222
}
2323

24-
bool ZSwapObject::CheckEnabled(const std::string& Value)
24+
bool ZSwapObject::CheckEnabled(const std::string& Value) const
2525
{
2626
return !std::regex_match(Value, std::regex("^[YN]$"));
2727
}
2828

29-
void ZSwapObject::WriteLogEntry(const std::string& Name, const std::string& Value)
29+
void ZSwapObject::WriteLogEntry(const std::string& Name, const std::string& Value) const
3030
{
3131
std::cout << std::vformat(ZSwapMessageLog, std::make_format_args(Name, Value)) << std::endl;
3232
}
3333

34-
void ZSwapObject::WriteZSwapValue(const std::string& Name, const std::string& Value)
34+
void ZSwapObject::WriteZSwapValue(const std::string& Name, const std::string& Value) const
3535
{
3636
const std::string FullPath = ZSwapModuleParametersPath + Name;
3737
if (!std::filesystem::exists(FullPath)) throw std::runtime_error(std::vformat(ZSwapErrorKernel, std::make_format_args(Name)));
@@ -40,7 +40,7 @@ void ZSwapObject::WriteZSwapValue(const std::string& Name, const std::string& Va
4040
ZSwapSysFs.close();
4141
}
4242

43-
std::string ZSwapObject::ReadZSwapValue(const std::string& Name)
43+
std::string ZSwapObject::ReadZSwapValue(const std::string& Name) const
4444
{
4545
const std::string FullPath = ZSwapModuleParametersPath + Name;
4646
if (!std::filesystem::exists(FullPath)) return "N/A";
@@ -51,115 +51,115 @@ std::string ZSwapObject::ReadZSwapValue(const std::string& Name)
5151
return Result;
5252
}
5353

54-
std::string ZSwapObject::GetZSwapEnabled()
54+
std::string ZSwapObject::GetZSwapEnabled() const
5555
{
5656
return ReadZSwapValue(ZSwapEnabledName);
5757
}
5858

59-
void ZSwapObject::SetZSwapEnabled(const std::string& Value)
59+
void ZSwapObject::SetZSwapEnabled(const std::string& Value) const
6060
{
6161
if (CheckEnabled(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorBool, std::make_format_args(ZSwapEnabledName)));
6262
WriteLogEntry(ZSwapEnabledName, Value);
6363
WriteZSwapValue(ZSwapEnabledName, Value);
6464
}
6565

66-
std::string ZSwapObject::GetZSwapSameFilledPages()
66+
std::string ZSwapObject::GetZSwapSameFilledPages() const
6767
{
6868
return ReadZSwapValue(ZSwapSameFilledPagesName);
6969
}
7070

71-
void ZSwapObject::SetZSwapSameFilledPages(const std::string& Value)
71+
void ZSwapObject::SetZSwapSameFilledPages(const std::string& Value) const
7272
{
7373
if (CheckEnabled(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorBool, std::make_format_args(ZSwapSameFilledPagesName)));
7474
WriteLogEntry(ZSwapSameFilledPagesName, Value);
7575
WriteZSwapValue(ZSwapSameFilledPagesName, Value);
7676
}
7777

78-
std::string ZSwapObject::GetZSwapMaxPoolPercent()
78+
std::string ZSwapObject::GetZSwapMaxPoolPercent() const
7979
{
8080
return ReadZSwapValue(ZSwapMaxPoolPercentName);
8181
}
8282

83-
void ZSwapObject::SetZSwapMaxPoolPercent(const std::string& Value)
83+
void ZSwapObject::SetZSwapMaxPoolPercent(const std::string& Value) const
8484
{
8585
if (CheckPercent(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorRange, std::make_format_args(ZSwapMaxPoolPercentName)));
8686
WriteLogEntry(ZSwapMaxPoolPercentName, Value);
8787
WriteZSwapValue(ZSwapMaxPoolPercentName, Value);
8888
}
8989

90-
std::string ZSwapObject::GetZSwapCompressor()
90+
std::string ZSwapObject::GetZSwapCompressor() const
9191
{
9292
return ReadZSwapValue(ZSwapCompressorName);
9393
}
9494

95-
void ZSwapObject::SetZSwapCompressor(const std::string& Value)
95+
void ZSwapObject::SetZSwapCompressor(const std::string& Value) const
9696
{
9797
if (Value.empty()) throw std::invalid_argument(std::vformat(ZSwapErrorEmpty, std::make_format_args(ZSwapCompressorName)));
9898
WriteLogEntry(ZSwapCompressorName, Value);
9999
WriteZSwapValue(ZSwapCompressorName, Value);
100100
}
101101

102-
std::string ZSwapObject::GetZSwapZpool()
102+
std::string ZSwapObject::GetZSwapZpool() const
103103
{
104104
return ReadZSwapValue(ZSwapZpoolName);
105105
}
106106

107-
void ZSwapObject::SetZSwapZpool(const std::string& Value)
107+
void ZSwapObject::SetZSwapZpool(const std::string& Value) const
108108
{
109109
if (Value.empty()) throw std::invalid_argument(std::vformat(ZSwapErrorEmpty, std::make_format_args(ZSwapZpoolName)));
110110
WriteLogEntry(ZSwapZpoolName, Value);
111111
WriteZSwapValue(ZSwapZpoolName, Value);
112112
}
113113

114-
std::string ZSwapObject::GetZSwapAcceptThresholdPercent()
114+
std::string ZSwapObject::GetZSwapAcceptThresholdPercent() const
115115
{
116116
return ReadZSwapValue(ZSwapAcceptThresholdPercentName);
117117
}
118118

119-
void ZSwapObject::SetZSwapAcceptThresholdPercent(const std::string& Value)
119+
void ZSwapObject::SetZSwapAcceptThresholdPercent(const std::string& Value) const
120120
{
121121
if (CheckPercent(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorRange, std::make_format_args(ZSwapAcceptThresholdPercentName)));
122122
WriteLogEntry(ZSwapAcceptThresholdPercentName, Value);
123123
WriteZSwapValue(ZSwapAcceptThresholdPercentName, Value);
124124
}
125125

126-
std::string ZSwapObject::GetZSwapNonSameFilledPages()
126+
std::string ZSwapObject::GetZSwapNonSameFilledPages() const
127127
{
128128
return ReadZSwapValue(ZSwapNonSameFilledPagesName);
129129
}
130130

131-
void ZSwapObject::SetZSwapNonSameFilledPages(const std::string& Value)
131+
void ZSwapObject::SetZSwapNonSameFilledPages(const std::string& Value) const
132132
{
133133
if (CheckEnabled(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorBool, std::make_format_args(ZSwapNonSameFilledPagesName)));
134134
WriteLogEntry(ZSwapNonSameFilledPagesName, Value);
135135
WriteZSwapValue(ZSwapNonSameFilledPagesName, Value);
136136
}
137137

138-
std::string ZSwapObject::GetZSwapExclusiveLoads()
138+
std::string ZSwapObject::GetZSwapExclusiveLoads() const
139139
{
140140
return ReadZSwapValue(ZSwapExclusiveLoadsName);
141141
}
142142

143-
void ZSwapObject::SetZSwapExclusiveLoads(const std::string& Value)
143+
void ZSwapObject::SetZSwapExclusiveLoads(const std::string& Value) const
144144
{
145145
if (CheckEnabled(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorBool, std::make_format_args(ZSwapExclusiveLoadsName)));
146146
WriteLogEntry(ZSwapExclusiveLoadsName, Value);
147147
WriteZSwapValue(ZSwapExclusiveLoadsName, Value);
148148
}
149149

150-
std::string ZSwapObject::GetZSwapShrinkerEnabled()
150+
std::string ZSwapObject::GetZSwapShrinkerEnabled() const
151151
{
152152
return ReadZSwapValue(ZSwapShrinkerEnabledName);
153153
}
154154

155-
void ZSwapObject::SetZSwapShrinkerEnabled(const std::string& Value)
155+
void ZSwapObject::SetZSwapShrinkerEnabled(const std::string& Value) const
156156
{
157157
if (CheckEnabled(Value)) throw std::invalid_argument(std::vformat(ZSwapErrorBool, std::make_format_args(ZSwapShrinkerEnabledName)));
158158
WriteLogEntry(ZSwapShrinkerEnabledName, Value);
159159
WriteZSwapValue(ZSwapShrinkerEnabledName, Value);
160160
}
161161

162-
bool ZSwapObject::IsAvailable()
162+
bool ZSwapObject::IsAvailable() const
163163
{
164164
return std::filesystem::exists(ZSwapModuleParametersPath);
165165
}

src/lib/zswapobject/zswapobject.hpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,133 +29,133 @@ class ZSwapObject
2929
* Gets the ZSwap enabled value.
3030
* @returns ZSwap enabled value.
3131
*/
32-
std::string GetZSwapEnabled();
32+
std::string GetZSwapEnabled() const;
3333

3434
/**
3535
* Sets the ZSwap enabled value.
3636
* @param Value New value.
3737
* @exception Raises an instance of std::invalid_argument if cannot set
3838
* the proposed value.
3939
*/
40-
void SetZSwapEnabled(const std::string&);
40+
void SetZSwapEnabled(const std::string&) const;
4141

4242
/**
4343
* Gets the same filled pages enabled value.
4444
* @returns Same filled pages enabled value.
4545
*/
46-
std::string GetZSwapSameFilledPages();
46+
std::string GetZSwapSameFilledPages() const;
4747

4848
/**
4949
* Sets the same filled pages enabled value.
5050
* @param Value New value.
5151
* @exception Raises an instance of std::invalid_argument if cannot set
5252
* the proposed value.
5353
*/
54-
void SetZSwapSameFilledPages(const std::string&);
54+
void SetZSwapSameFilledPages(const std::string&) const;
5555

5656
/**
5757
* Gets the maximum pool percentage value.
5858
* @returns Maximum pool percentage value.
5959
*/
60-
std::string GetZSwapMaxPoolPercent();
60+
std::string GetZSwapMaxPoolPercent() const;
6161

6262
/**
6363
* Sets the maximum pool percentage value.
6464
* @param Value New value.
6565
* @exception Raises an instance of std::invalid_argument if cannot set
6666
* the proposed value.
6767
*/
68-
void SetZSwapMaxPoolPercent(const std::string&);
68+
void SetZSwapMaxPoolPercent(const std::string&) const;
6969

7070
/**
7171
* Gets the compression algorithm name.
7272
* @returns Compression algorithm name.
7373
*/
74-
std::string GetZSwapCompressor();
74+
std::string GetZSwapCompressor() const;
7575

7676
/**
7777
* Sets the compression algorithm name.
7878
* @param Value New value.
7979
* @exception Raises an instance of std::invalid_argument if cannot set
8080
* the proposed value.
8181
*/
82-
void SetZSwapCompressor(const std::string&);
82+
void SetZSwapCompressor(const std::string&) const;
8383

8484
/**
8585
* Gets the kernel's zpool type.
8686
* @returns Kernel's zpool type.
8787
*/
88-
std::string GetZSwapZpool();
88+
std::string GetZSwapZpool() const;
8989

9090
/**
9191
* Sets the kernel's zpool type.
9292
* @param Value New value.
9393
* @exception Raises an instance of std::invalid_argument if cannot set
9494
* the proposed value.
9595
*/
96-
void SetZSwapZpool(const std::string&);
96+
void SetZSwapZpool(const std::string&) const;
9797

9898
/**
9999
* Gets the accept threshold percentage value.
100100
* @returns Accept threshold percentage value.
101101
*/
102-
std::string GetZSwapAcceptThresholdPercent();
102+
std::string GetZSwapAcceptThresholdPercent() const;
103103

104104
/**
105105
* Sets the accept threshold percentage value.
106106
* @param Value New value.
107107
* @exception Raises an instance of std::invalid_argument if cannot set
108108
* the proposed value.
109109
*/
110-
void SetZSwapAcceptThresholdPercent(const std::string&);
110+
void SetZSwapAcceptThresholdPercent(const std::string&) const;
111111

112112
/**
113113
* Gets the non same filled pages enabled value.
114114
* @returns Non same filled pages enabled value.
115115
*/
116-
std::string GetZSwapNonSameFilledPages();
116+
std::string GetZSwapNonSameFilledPages() const;
117117

118118
/**
119119
* Sets the non same filled pages enabled value.
120120
* @param Value New value.
121121
* @exception Raises an instance of std::invalid_argument if cannot set
122122
* the proposed value.
123123
*/
124-
void SetZSwapNonSameFilledPages(const std::string&);
124+
void SetZSwapNonSameFilledPages(const std::string&) const;
125125

126126
/**
127127
* Gets the exclusive loads enabled value.
128128
* @returns Exclusive loads enabled value.
129129
*/
130-
std::string GetZSwapExclusiveLoads();
130+
std::string GetZSwapExclusiveLoads() const;
131131

132132
/**
133133
* Sets the exclusive loads enabled value.
134134
* @param Value New value.
135135
* @exception Raises an instance of std::invalid_argument if cannot set
136136
* the proposed value.
137137
*/
138-
void SetZSwapExclusiveLoads(const std::string&);
138+
void SetZSwapExclusiveLoads(const std::string&) const;
139139

140140
/**
141141
* Gets the shrinker enabled value.
142142
* @returns Shrinker enabled value.
143143
*/
144-
std::string GetZSwapShrinkerEnabled();
144+
std::string GetZSwapShrinkerEnabled() const;
145145

146146
/**
147147
* Sets the shrinker enabled value.
148148
* @param Value New value.
149149
* @exception Raises an instance of std::invalid_argument if cannot set
150150
* the proposed value.
151151
*/
152-
void SetZSwapShrinkerEnabled(const std::string&);
152+
void SetZSwapShrinkerEnabled(const std::string&) const;
153153

154154
/**
155155
* Checks if the ZSwap module is loaded and available for use.
156156
* @returns ZSwap module availability.
157157
*/
158-
bool IsAvailable();
158+
bool IsAvailable() const;
159159
private:
160160
/**
161161
* Stores the ZSwap log message template.
@@ -237,7 +237,7 @@ class ZSwapObject
237237
* @param Name Name.
238238
* @param Value Value.
239239
*/
240-
void WriteZSwapValue(const std::string&, const std::string&);
240+
void WriteZSwapValue(const std::string&, const std::string&) const;
241241

242242
/**
243243
* Reads the value of the ZSwap kernel module by specified name.
@@ -246,14 +246,14 @@ class ZSwapObject
246246
* the proposed value.
247247
* @returns Value.
248248
*/
249-
std::string ReadZSwapValue(const std::string&);
249+
std::string ReadZSwapValue(const std::string&) const;
250250

251251
/**
252252
* Prints log entry to the standard output.
253253
* @param Name Parameter name.
254254
* @param Value Parameter value.
255255
*/
256-
void WriteLogEntry(const std::string&, const std::string&);
256+
void WriteLogEntry(const std::string&, const std::string&) const;
257257

258258
/**
259259
* Checks if the value matches the specified criteria [0..100].
@@ -262,7 +262,7 @@ class ZSwapObject
262262
* @retval true If the value belongs to [0..100] range.
263263
* @retval false Otherwise.
264264
*/
265-
bool CheckPercent(const std::string&);
265+
bool CheckPercent(const std::string&) const;
266266

267267
/**
268268
* Checks if the value matches the specified criteria (Y or N).
@@ -271,7 +271,7 @@ class ZSwapObject
271271
* @retval true If the value matches the specified criteria.
272272
* @retval false Otherwise.
273273
*/
274-
bool CheckEnabled(const std::string&);
274+
bool CheckEnabled(const std::string&) const;
275275
};
276276

277277
#endif // ZSWAPOBJECT_HPP

0 commit comments

Comments
 (0)