Skip to content

Commit ea29d64

Browse files
authored
Merge pull request #16 from dezed-ukaea/main
Some smells
2 parents 5746701 + b781983 commit ea29d64

File tree

8 files changed

+85
-70
lines changed

8 files changed

+85
-70
lines changed

include/fdp/exceptions.hxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@
77
namespace FDP {
88
class config_parsing_error : public std::runtime_error {
99
public:
10-
config_parsing_error(const std::string message)
10+
config_parsing_error(const std::string& message)
1111
: std::runtime_error(message) {}
1212
};
1313

1414
class rest_apiquery_error : public std::runtime_error {
1515
public:
16-
rest_apiquery_error(const std::string message)
16+
rest_apiquery_error(const std::string& message)
1717
: std::runtime_error(message) {}
1818
};
1919

2020
class json_parse_error : public std::runtime_error {
2121
public:
22-
json_parse_error(const std::string message) : std::runtime_error(message) {}
22+
json_parse_error(const std::string& message) : std::runtime_error(message) {}
2323
};
2424

2525
class validation_error : public std::runtime_error {
2626
public:
27-
validation_error(const std::string message) : std::runtime_error(message) {}
27+
validation_error(const std::string& message) : std::runtime_error(message) {}
2828
};
2929

3030
class sync_error : public std::runtime_error {
3131
public:
32-
sync_error(const std::string message) : std::runtime_error(message) {}
32+
sync_error(const std::string& message) : std::runtime_error(message) {}
3333
};
3434

3535
class write_error : public std::runtime_error {
3636
public:
37-
write_error(const std::string message) : std::runtime_error(message) {}
37+
write_error(const std::string& message) : std::runtime_error(message) {}
3838
};
3939

4040
}; // namespace FDP
4141

42-
#endif
42+
#endif

include/fdp/objects/api_object.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace FDP {
1616
private:
1717
Json::Value obj_;
1818

19+
protected:
1920
ApiObject();
2021

2122
public:
@@ -71,15 +72,15 @@ namespace FDP {
7172
* @param key
7273
* @return std::string
7374
*/
74-
std::string get_value_as_string(std::string key) const;
75+
std::string get_value_as_string( const std::string& key) const;
7576

7677
/**
7778
* @brief Get the value of a given key as int object
7879
*
7980
* @param key
8081
* @return int
8182
*/
82-
int get_value_as_int(std::string key) const;
83+
int get_value_as_int( const std::string& key) const;
8384

8485
/**
8586
* @brief Get the first component of the object
@@ -96,6 +97,6 @@ namespace FDP {
9697
*/
9798
bool is_empty();
9899
};
99-
};
100100

101+
}
101102
#endif

include/fdp/objects/config.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ namespace FDP {
214214
/**
215215
* @brief Get the code run uuid
216216
*
217-
* @return std::string
217+
* @return const std::string&
218218
*/
219219
std::string get_code_run_uuid() const;
220220

@@ -263,14 +263,14 @@ namespace FDP {
263263
*
264264
* @return std::shared_ptr<API>
265265
*/
266-
API::sptr get_api(){return api_;}
266+
API::sptr get_api() const {return api_;}
267267

268268
/**
269269
* @brief Get the rest api location (local / remote)
270270
*
271271
* @return RESTAPI
272272
*/
273-
RESTAPI get_rest_api_location(){return rest_api_location_;}
273+
RESTAPI get_rest_api_location() const {return rest_api_location_;}
274274

275275
};
276276
};

include/fdp/objects/io_object.hxx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace FDP {
3333
* @brief Construct a new IOObject object (empty constructor)
3434
*
3535
*/
36-
IOObject(){};
36+
IOObject() = default;
3737
/**
3838
* @brief Construct a new IOObject object
3939
* Used to store inputs and outputs for in the config
@@ -46,12 +46,12 @@ namespace FDP {
4646
* @param data_product_description data product description
4747
* @param isPublic whether or not the data product should be public
4848
*/
49-
IOObject(std::string data_product,
50-
std::string use_data_product,
51-
std::string use_version,
52-
std::string use_namespace,
49+
IOObject (const std::string& data_product,
50+
const std::string& use_data_product,
51+
const std::string& use_version,
52+
const std::string& use_namespace,
5353
ghc::filesystem::path path,
54-
std::string data_product_description,
54+
const std::string& data_product_description,
5555
bool isPublic)
5656
:
5757
data_product_(data_product),
@@ -74,10 +74,10 @@ namespace FDP {
7474
* @param component_obj the data_product component object as a shared pointer
7575
* @param data_product_obj the data_product object as a shared pointer
7676
*/
77-
IOObject(std::string data_product,
78-
std::string use_data_product,
79-
std::string use_version,
80-
std::string use_namespace,
77+
IOObject( const std::string& data_product,
78+
const std::string& use_data_product,
79+
const std::string& use_version,
80+
const std::string& use_namespace,
8181
ghc::filesystem::path path,
8282
ApiObject &component_obj,
8383
ApiObject &data_product_obj)
@@ -93,81 +93,81 @@ namespace FDP {
9393
/**
9494
* @brief Get the data product as a string
9595
*
96-
* @return std::string
96+
* @return const std::string&
9797
*/
98-
std::string get_data_product() {return data_product_;}
98+
const std::string& get_data_product() const {return data_product_;}
9999

100100
/**
101101
* @brief Get the use data product as a string
102102
*
103-
* @return std::string
103+
* @return const std::string&
104104
*/
105-
std::string get_use_data_product() {return use_data_product_;}
105+
const std::string& get_use_data_product() const {return use_data_product_;}
106106

107107
/**
108108
* @brief Get the use component as a string
109109
*
110-
* @return std::string
110+
* @return const std::string&
111111
*/
112-
std::string get_use_component() {return use_component_;}
112+
const std::string& get_use_component() const {return use_component_;}
113113

114114
/**
115115
* @brief Get the use version as a string
116116
*
117-
* @return std::string
117+
* @return const std::string&
118118
*/
119-
std::string get_use_version() {return use_version_;}
119+
const std::string& get_use_version() const {return use_version_;}
120120

121121
/**
122122
* @brief Get the use namespace as a string
123123
*
124-
* @return std::string
124+
* @return const std::string&
125125
*/
126-
std::string get_use_namespace() {return use_namespace_;}
126+
const std::string& get_use_namespace() {return use_namespace_;}
127127

128128
/**
129129
* @brief Get the path of the data product
130130
*
131131
* @return ghc::filesystem::path
132132
*/
133-
ghc::filesystem::path get_path() {return path_;}
133+
ghc::filesystem::path get_path() const {return path_;}
134134

135135
/**
136136
* @brief Get the data product description as a string
137137
*
138138
* @return std::string
139139
*/
140-
std::string get_data_product_description() {return data_product_description_;}
140+
const std::string& get_data_product_description() const {return data_product_description_;}
141141

142142
/**
143143
* @brief Get the component description as a string
144144
*
145145
* @return std::string
146146
*/
147-
std::string get_component_description() {return component_description_;}
147+
const std::string& get_component_description() {return component_description_;}
148148

149149
/**
150150
* @brief Check whether the data product is public
151151
*
152152
* @return true the data product is public
153153
* @return false the data product is not public
154154
*/
155-
bool is_public() {return public_;}
155+
bool is_public() const {return public_;}
156156

157157
/**
158158
* @brief Get the component object object
159159
*
160160
* @return std::shared_ptr<ApiObject>
161161
*/
162-
ApiObject::sptr get_component_object() {return component_obj_;}
162+
ApiObject::sptr get_component_object() const {return component_obj_;}
163163

164164

165165
/**
166166
* @brief Get the data product object object
167167
*
168168
* @return std::shared_ptr<ApiObject>
169169
*/
170-
ApiObject::sptr get_data_product_object() {return data_product_obj_;}
170+
ApiObject::sptr get_data_product_object() const {return data_product_obj_;}
171171

172172
/**
173173
* @brief Set the component object object

include/fdp/utilities/logging.hxx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
#include "spdlog/spdlog.h"
1616

1717
namespace FDP {
18-
/*! **************************************************************************
19-
* @brief Create a the global logger pointer
20-
* @author K. Zarebski (UKAEA)
21-
*
22-
* @return a shared pointer to the global logger instance
23-
****************************************************************************/
24-
std::shared_ptr<spdlog::logger> create_logger_();
2518

26-
/**
27-
* @brief Global logger used across all FDP scripts
28-
* @author K. Zarebski (UKAEA)
29-
*
30-
*/
31-
const std::shared_ptr<spdlog::logger> APILogger = create_logger_();
19+
class logger
20+
{
21+
public:
22+
typedef std::shared_ptr<spdlog::logger> sptr;
23+
private:
24+
};
25+
26+
/**
27+
* @brief Global logger used across all FDP scripts
28+
* @author K. Zarebski (UKAEA)
29+
*
30+
*/
31+
extern const logger::sptr APILogger;
3232
} // namespace FDP
3333

34-
#endif
34+
35+
36+
#endif

src/fdp.cxx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ namespace FDP {
3636
ghc::filesystem::path script_file_path_() const {return config_->get_script_file_path();}
3737
std::string token_() const {return config_->get_token();}
3838
RESTAPI api_location_() {return config_->get_rest_api_location();}
39+
40+
impl& operator=(const impl& ) = delete;
41+
3942
public:
4043
typedef std::shared_ptr< impl > sptr;
4144

@@ -49,11 +52,11 @@ namespace FDP {
4952
***************************************************************************/
5053
impl(const ghc::filesystem::path &config_file_path,
5154
const ghc::filesystem::path &file_system_path,
52-
const std::string token,
55+
const std::string& token,
5356
spdlog::level::level_enum log_level = spdlog::level::info,
5457
RESTAPI api_location = RESTAPI::LOCAL);
5558

56-
impl(const impl &dp);
59+
//impl(const impl &dp) delete;
5760

5861
/**
5962
* @brief Default Destructor
@@ -97,10 +100,10 @@ namespace FDP {
97100
*
98101
* @return std::string
99102
*/
100-
std::string get_code_run_uuid();
103+
std::string get_code_run_uuid() const;
101104

102105
};
103-
106+
#if 0
104107
DataPipeline::impl::impl(const impl &dp)
105108
{
106109
impl( dp.config_file_path_()
@@ -109,11 +112,11 @@ DataPipeline::impl::impl(const impl &dp)
109112
, api_location_()
110113
);
111114
}
112-
115+
#endif
113116

114117
DataPipeline::impl::impl(const ghc::filesystem::path &config_file_path,
115118
const ghc::filesystem::path &script_file_path,
116-
const std::string token,
119+
const std::string& token,
117120
spdlog::level::level_enum log_level,
118121
RESTAPI api_location)
119122
{
@@ -140,7 +143,7 @@ void FDP::DataPipeline::impl::finalise(){
140143
config_->finalise();
141144
}
142145

143-
std::string FDP::DataPipeline::impl::get_code_run_uuid(){
146+
std::string FDP::DataPipeline::impl::get_code_run_uuid() const {
144147
return config_->get_code_run_uuid();
145148
}
146149

src/objects/api_object.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ namespace FDP {
9090
return obj_["url"].asString();
9191
}
9292

93-
std::string ApiObject::get_value_as_string(std::string key) const{
93+
std::string ApiObject::get_value_as_string( const std::string& key) const{
9494
return obj_[key].asString();
9595
}
96-
int ApiObject::get_value_as_int(std::string key) const{
96+
int ApiObject::get_value_as_int(const std::string& key) const{
9797
return obj_[key].asInt();
9898
}
9999

src/utilities/logging.cxx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#include "fdp/utilities/logging.hxx"
22

33
namespace FDP {
4-
std::shared_ptr<spdlog::logger> create_logger_() {
5-
if (!spdlog::get("FDPAPI")) {
6-
return spdlog::stdout_color_st("FDPAPI");
7-
} else {
8-
return spdlog::get("FDPAPI");
9-
}
10-
}
11-
} // namespace FDP
4+
5+
/*! **************************************************************************
6+
* @brief Create a the global logger pointer
7+
* @author K. Zarebski (UKAEA)
8+
*
9+
* @return a shared pointer to the global logger instance
10+
****************************************************************************/
11+
static logger::sptr create_logger() {
12+
if (!spdlog::get("FDPAPI")) {
13+
return spdlog::stdout_color_st("FDPAPI");
14+
} else {
15+
return spdlog::get("FDPAPI");
16+
}
17+
}
18+
19+
const logger::sptr APILogger = create_logger();
20+
} // namespace FDP

0 commit comments

Comments
 (0)