Skip to content

Commit 2aeed81

Browse files
committed
typedef smart pointers. Reorganise DatapipeLine pimpl to hide the impl
1 parent 5eb4d90 commit 2aeed81

File tree

9 files changed

+219
-170
lines changed

9 files changed

+219
-170
lines changed

include/fdp/fdp.hxx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
#ifndef __FDP__
2+
#define __FDP__
3+
4+
#include <ghc/filesystem.hpp>
5+
16
#include "fdp/registry/datapipeline.hxx"
27

38
namespace FDP {
9+
410
class DataPipeline {
11+
512
public:
613
// 'initialise' method for the API
14+
15+
~DataPipeline();
16+
717
explicit DataPipeline(
818
const std::string &config_file_path,
919
const std::string &script_file_path,
1020
std::string token = "",
11-
spdlog::level::level_enum log_level = spdlog::level::info)
12-
: pimpl_(std::make_shared<DataPipelineImpl_>(ghc::filesystem::path(config_file_path), ghc::filesystem::path(script_file_path), token,
13-
log_level)) {
14-
15-
APILogger->debug("DataPipeline: Initialising session '{0}'", Pimpl()->get_code_run_uuid());
16-
}
17-
18-
// 'finalise' method for the API
19-
~DataPipeline();
21+
spdlog::level::level_enum log_level = spdlog::level::info);
22+
2023

2124
DataPipeline(DataPipeline &&rhs) noexcept;
2225
DataPipeline &operator=(DataPipeline &&rhs) noexcept;
@@ -29,9 +32,10 @@ public:
2932
void finalise();
3033

3134
private:
32-
const DataPipelineImpl_* Pimpl() const {return pimpl_.get();}
33-
DataPipelineImpl_* Pimpl() {return pimpl_.get();}
34-
35-
std::shared_ptr<DataPipelineImpl_> pimpl_;
35+
class impl;
36+
37+
std::shared_ptr< DataPipeline::impl > pimpl_;
3638
};
37-
}; // namespace FDP
39+
}; // namespace FDP
40+
41+
#endif

include/fdp/objects/api_object.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ namespace FDP {
1616
private:
1717
Json::Value obj_;
1818
public:
19+
20+
typedef std::unique_ptr< ApiObject > uptr;
21+
typedef std::shared_ptr< ApiObject > sptr;
22+
1923
ApiObject() : obj_(Json::Value()){};
2024
/**
2125
* @brief Construct a new Api Object object
@@ -57,4 +61,4 @@ namespace FDP {
5761
};
5862
};
5963

60-
#endif
64+
#endif

include/fdp/objects/config.hxx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ namespace FDP {
4141
std::string token_;
4242
std::shared_ptr<API> api_;
4343

44-
std::unique_ptr<ApiObject> user_;
45-
std::unique_ptr<ApiObject> author_;
44+
ApiObject::uptr user_;
45+
ApiObject::uptr author_;
4646

47-
std::unique_ptr<ApiObject> config_storage_root_;
48-
std::unique_ptr<ApiObject> config_storage_location_;
49-
std::unique_ptr<ApiObject> config_file_type_;
50-
std::unique_ptr<ApiObject> config_obj_;
47+
ApiObject::uptr config_storage_root_;
48+
ApiObject::uptr config_storage_location_;
49+
ApiObject::uptr config_file_type_;
50+
ApiObject::uptr config_obj_;
5151

52-
std::unique_ptr<ApiObject> script_storage_root_;
53-
std::unique_ptr<ApiObject> script_storage_location_;
54-
std::unique_ptr<ApiObject> script_file_type_;
55-
std::unique_ptr<ApiObject> script_obj_;
52+
ApiObject::uptr script_storage_root_;
53+
ApiObject::uptr script_storage_location_;
54+
ApiObject::uptr script_file_type_;
55+
ApiObject::uptr script_obj_;
5656

57-
std::unique_ptr<ApiObject> code_repo_storage_root_;
58-
std::unique_ptr<ApiObject> code_repo_storage_location_;
59-
std::unique_ptr<ApiObject> code_repo_obj_;
57+
ApiObject::uptr code_repo_storage_root_;
58+
ApiObject::uptr code_repo_storage_location_;
59+
ApiObject::uptr code_repo_obj_;
6060

61-
std::unique_ptr<ApiObject> code_run_;
61+
ApiObject::uptr code_run_;
6262

6363
std::map<std::string, IOObject> writes_;
6464
std::map<std::string, IOObject> reads_;
@@ -72,6 +72,8 @@ namespace FDP {
7272
bool config_has_reads() const;
7373

7474
public:
75+
typedef std::unique_ptr< Config > uptr;
76+
7577
Config(const ghc::filesystem::path &config_file_path,
7678
const ghc::filesystem::path &script_file_path,
7779
const std::string &token,
@@ -117,4 +119,4 @@ namespace FDP {
117119

118120
};
119121
};
120-
#endif
122+
#endif

include/fdp/objects/io_object.hxx

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,42 @@ namespace FDP {
2525
std::string component_description_ = "None";
2626
bool public_ = false;
2727

28-
std::shared_ptr<ApiObject> component_obj_;
29-
std::shared_ptr<ApiObject> data_product_obj_;
28+
ApiObject::sptr component_obj_;
29+
ApiObject::sptr data_product_obj_;
3030

3131
public:
3232
IOObject(){};
3333
IOObject(std::string data_product,
34-
std::string use_data_product,
35-
std::string use_version,
36-
std::string use_namespace,
37-
ghc::filesystem::path path,
38-
std::string data_product_description,
39-
bool isPublic):
40-
data_product_(data_product),
41-
use_data_product_(use_data_product),
42-
use_version_(use_version),
43-
use_namespace_(use_namespace),
44-
path_(path),
45-
data_product_description_(data_product_description),
46-
public_(isPublic){};
34+
std::string use_data_product,
35+
std::string use_version,
36+
std::string use_namespace,
37+
ghc::filesystem::path path,
38+
std::string data_product_description,
39+
bool isPublic)
40+
:
41+
data_product_(data_product),
42+
use_data_product_(use_data_product),
43+
use_version_(use_version),
44+
use_namespace_(use_namespace),
45+
path_(path),
46+
data_product_description_(data_product_description),
47+
public_(isPublic){};
4748

4849
IOObject(std::string data_product,
4950
std::string use_data_product,
5051
std::string use_version,
5152
std::string use_namespace,
5253
ghc::filesystem::path path,
5354
ApiObject &component_obj,
54-
ApiObject &data_product_obj):
55-
data_product_(data_product),
56-
use_data_product_(use_data_product),
57-
use_version_(use_version),
58-
use_namespace_(use_namespace),
59-
path_(path),
60-
component_obj_(std::make_shared<ApiObject>(component_obj)),
61-
data_product_obj_(std::make_shared<ApiObject>(data_product_obj)){};
55+
ApiObject &data_product_obj)
56+
:
57+
data_product_(data_product),
58+
use_data_product_(use_data_product),
59+
use_version_(use_version),
60+
use_namespace_(use_namespace),
61+
path_(path),
62+
component_obj_(std::make_shared<ApiObject>(component_obj)),
63+
data_product_obj_(std::make_shared<ApiObject>(data_product_obj)){};
6264

6365
std::string get_data_product() {return data_product_;}
6466
std::string get_use_data_product() {return use_data_product_;}
@@ -70,12 +72,12 @@ namespace FDP {
7072
std::string get_component_description() {return component_description_;}
7173
bool is_public() {return public_;}
7274

73-
std::shared_ptr<ApiObject> get_component_object() {return component_obj_;}
74-
std::shared_ptr<ApiObject> get_data_product_object() {return data_product_obj_;}
75+
ApiObject::sptr get_component_object() {return component_obj_;}
76+
ApiObject::sptr get_data_product_object() {return data_product_obj_;}
7577

76-
void set_component_object(ApiObject &component_obj){component_obj_ = std::make_shared<ApiObject>(component_obj);}
78+
void set_component_object(ApiObject& component_obj){component_obj_ = std::make_shared<ApiObject>(component_obj);}
7779
void set_data_product_object(ApiObject &data_product_obj){data_product_obj_ = std::make_shared<ApiObject>(data_product_obj);}
7880
};
7981
};
8082

81-
#endif
83+
#endif

include/fdp/registry/datapipeline.hxx

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* with the FDP FAIR Data pipeline. They contain methods which parse
99
* configurations and control calls to the RestAPI itself.
1010
****************************************************************************/
11-
#ifndef __FDP_DATAPIPELINE_HXX__
12-
#define __FDP_DATAPIPELINE_HXX__
11+
#ifndef __FDP_DATAPIPELINE_IMP_HXX__
12+
#define __FDP_DATAPIPELINE_IMP_HXX__
1313

1414
#include <algorithm>
1515
#include <fstream>
@@ -19,6 +19,8 @@
1919
#include "spdlog/spdlog.h"
2020
#include "json/json.h"
2121

22+
#include "fdp/fdp.hxx"
23+
2224
#include "fdp/objects/config.hxx"
2325
#include "fdp/objects/metadata.hxx"
2426
#include "fdp/registry/api.hxx"
@@ -42,51 +44,6 @@ namespace FDP {
4244
* but rather via an FDP::DataPipeline instance.
4345
*
4446
*****************************************************************************/
45-
class DataPipelineImpl_ {
46-
private:
47-
std::unique_ptr<Config> config_;
48-
49-
ghc::filesystem::path config_file_path_() const {return config_->get_config_file_path();}
50-
ghc::filesystem::path script_file_path_() const {return config_->get_script_file_path();}
51-
std::string token_() const {return config_->get_token();}
52-
RESTAPI api_location_() {return config_->get_rest_api_location();}
53-
public:
54-
55-
/*! *************************************************************************
56-
* @brief construct a DataPipelineImpl_ instance from configurations and setup
57-
* @author K. Zarebski (UKAEA)
58-
*
59-
* @param config_file_path location of the local configuration file
60-
* @param access_token_file API authorisation token where required
61-
* @param log_level level for the output logging statements
62-
* @param api_location whether to use local/remote RestAPI endpoint
63-
***************************************************************************/
64-
DataPipelineImpl_(const ghc::filesystem::path &config_file_path,
65-
const ghc::filesystem::path &file_system_path,
66-
const std::string token,
67-
spdlog::level::level_enum log_level = spdlog::level::info,
68-
RESTAPI api_location = RESTAPI::LOCAL);
69-
70-
DataPipelineImpl_(const DataPipelineImpl_ &dp){
71-
DataPipelineImpl_(dp.config_file_path_(), dp.script_file_path_(), token_(), spdlog::level::info, api_location_());}
72-
73-
/**
74-
* @brief Destroy the Data Pipeline Impl_ object
75-
*
76-
*/
77-
~DataPipelineImpl_() = default;
78-
79-
//DataPipelineImpl_& operator=(DataPipelineImpl_ dp);
80-
81-
82-
83-
ghc::filesystem::path link_read(std::string &data_product);
84-
ghc::filesystem::path link_write(std::string &data_product);
85-
void finalise();
86-
87-
std::string get_code_run_uuid();
88-
89-
};
9047
}; // namespace FDP
9148

92-
#endif
49+
#endif

0 commit comments

Comments
 (0)