Skip to content

Commit 1befba1

Browse files
committed
ApiObject private constructor to force common obj creation
1 parent 2aeed81 commit 1befba1

File tree

9 files changed

+306
-104
lines changed

9 files changed

+306
-104
lines changed

include/fdp/fdp.hxx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77

88
namespace FDP {
99

10-
class DataPipeline {
10+
class DataPipeline {
1111

12-
public:
13-
// 'initialise' method for the API
12+
public:
13+
// 'initialise' method for the API
1414

15-
~DataPipeline();
15+
~DataPipeline();
1616

17-
explicit DataPipeline(
18-
const std::string &config_file_path,
19-
const std::string &script_file_path,
20-
std::string token = "",
21-
spdlog::level::level_enum log_level = spdlog::level::info);
17+
explicit DataPipeline(
18+
const std::string &config_file_path,
19+
const std::string &script_file_path,
20+
std::string token = "",
21+
spdlog::level::level_enum log_level = spdlog::level::info);
2222

2323

24-
DataPipeline(DataPipeline &&rhs) noexcept;
25-
DataPipeline &operator=(DataPipeline &&rhs) noexcept;
24+
DataPipeline(DataPipeline &&rhs) noexcept;
25+
DataPipeline &operator=(DataPipeline &&rhs) noexcept;
2626

27-
DataPipeline(const DataPipeline &rhs);
28-
DataPipeline &operator=(const DataPipeline &rhs);
27+
DataPipeline(const DataPipeline &rhs);
28+
DataPipeline &operator=(const DataPipeline &rhs);
2929

30-
ghc::filesystem::path link_read(std::string &data_product);
31-
ghc::filesystem::path link_write(std::string &data_product);
32-
void finalise();
30+
ghc::filesystem::path link_read(std::string &data_product);
31+
ghc::filesystem::path link_write(std::string &data_product);
32+
void finalise();
3333

34-
private:
35-
class impl;
36-
37-
std::shared_ptr< DataPipeline::impl > pimpl_;
38-
};
34+
private:
35+
class impl;
36+
37+
std::shared_ptr< DataPipeline::impl > pimpl_;
38+
};
3939
}; // namespace FDP
4040

4141
#endif

include/fdp/objects/api_object.hxx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,34 @@ namespace FDP {
1515
class ApiObject {
1616
private:
1717
Json::Value obj_;
18+
19+
ApiObject();
20+
1821
public:
1922

2023
typedef std::unique_ptr< ApiObject > uptr;
2124
typedef std::shared_ptr< ApiObject > sptr;
2225

23-
ApiObject() : obj_(Json::Value()){};
26+
static uptr from_json( const Json::Value& j );
27+
28+
//static copy( const ApiObject& src );
29+
2430
/**
2531
* @brief Construct a new Api Object object
2632
*
2733
* @param uri uri of the api object e.g. http://127.0.0.1/object/1
2834
*/
29-
ApiObject(Json::Value obj) : obj_(obj){}
35+
36+
static ApiObject::uptr construct( void );
37+
38+
39+
int add( const std::string& key, int value );
40+
int add( const std::string& key, float value );
41+
int add( const std::string& key, double value );
42+
int add( const std::string& key, const std::string& value );
43+
int add( const std::string& key, const ApiObject& value );
44+
45+
int remove( const std::string& key );
3046
/**
3147
* @brief Get the object id from the uri
3248
*

include/fdp/objects/config.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace FDP {
3939
YAML::Node config_data_;
4040
std::string api_url_;
4141
std::string token_;
42-
std::shared_ptr<API> api_;
42+
API::sptr api_;
4343

4444
ApiObject::uptr user_;
4545
ApiObject::uptr author_;
@@ -113,7 +113,7 @@ namespace FDP {
113113

114114
YAML::Node get_config_data() const {return config_data_;}
115115

116-
std::shared_ptr<API> get_api(){return api_;}
116+
API::sptr get_api(){return api_;}
117117

118118
RESTAPI get_rest_api_location(){return rest_api_location_;}
119119

include/fdp/registry/api.hxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public:
117117
*****************************************************************************/
118118
class API {
119119
public:
120+
typedef std::shared_ptr< API > sptr;
121+
120122
/*! *************************************************************************
121123
* @brief construct an API object using the given URL as the root
122124
* @author K. Zarebski (UKAEA)
@@ -246,4 +248,4 @@ std::string url_encode(std::string url);
246248

247249
}; // namespace FDP
248250

249-
#endif
251+
#endif

src/fdp.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace FDP {
1212
std::string token_() const {return config_->get_token();}
1313
RESTAPI api_location_() {return config_->get_rest_api_location();}
1414
public:
15+
typedef std::shared_ptr< impl > sptr;
1516

1617
/*! *************************************************************************
1718
* @brief construct a DataPipelineImpl_ instance from configurations and setup

src/objects/api_object.cxx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,72 @@
11
#include "fdp/objects/api_object.hxx"
22

33
namespace FDP {
4+
5+
ApiObject::ApiObject() : obj_(Json::Value() )
6+
{
7+
}
8+
9+
ApiObject::uptr ApiObject::from_json( const Json::Value& j )
10+
{
11+
// ApiObject::uptr pobj = std::unique_ptr< ApiObject >( new ApiObject( j ) );
12+
13+
ApiObject::uptr pobj = ApiObject::construct();
14+
pobj->obj_ = j;
15+
16+
return pobj;
17+
}
18+
19+
ApiObject::uptr ApiObject::construct(void)
20+
{
21+
ApiObject::uptr pobj = std::unique_ptr< ApiObject >( new ApiObject() );
22+
return pobj;
23+
}
24+
#if 0
25+
ApiObject::uptr ApiObject::copy( const ApiObject& src )
26+
{
27+
ApiObject::uptr pobj = std::unique_ptr< ApiObject >( new ApiObject() );
28+
29+
pobj->obj_.copy( src.obj_ );
30+
return obj;
31+
}
32+
#endif
33+
int ApiObject::add( const std::string& key, int value )
34+
{
35+
this->obj_[ key ] = value;
36+
return 0;
37+
}
38+
int ApiObject::add( const std::string& key, float value )
39+
{
40+
this->obj_[ key ] = value;
41+
return 0;
42+
}
43+
44+
int ApiObject::add( const std::string& key, double value )
45+
{
46+
this->obj_[ key ] = value;
47+
return 0;
48+
}
49+
50+
int ApiObject::add( const std::string& key, const std::string& value )
51+
{
52+
this->obj_[ key ] = value;
53+
return 0;
54+
}
55+
56+
int ApiObject::add( const std::string& key, const ApiObject& value )
57+
{
58+
this->obj_[ key ] = value.obj_;
59+
return 0;
60+
}
61+
62+
63+
int ApiObject::remove( const std::string& key )
64+
{
65+
this->obj_.removeMember( key );
66+
return 0;
67+
}
68+
69+
470
/**
571
* @brief Returns the object id from the object uri_
672
*
@@ -51,4 +117,4 @@ namespace FDP {
51117
std::string ApiObject::get_first_component() const{
52118
return obj_["components"][0].asString();
53119
}
54-
};
120+
};

0 commit comments

Comments
 (0)