SatDump 2.0.0-alpha-520736c72
Loading...
Searching...
No Matches
product.h
Go to the documentation of this file.
1#pragma once
2
7
8#include "nlohmann/json.hpp"
9
10#define PRODUCT_LOADER_FUN(TYPE) \
11 [](std::string file) -> std::shared_ptr<Product> \
12 { \
13 std::shared_ptr<TYPE> product = std::make_shared<TYPE>(); \
14 product->load(file); \
15 return product; \
16 }
17
18namespace satdump
19{
20 namespace products
21 {
33 class Product
34 {
35 public: // protected:
36 nlohmann::json contents;
37
38 public:
39 std::string instrument_name;
40 std::string type;
41
42 public:
43 Product() {}
44 Product(Product const &) = delete;
45 void operator=(Product const &x) = delete;
46
47 public:
52 void set_product_timestamp(double timestamp) { contents["product_timestamp"] = timestamp; }
53
58 bool has_product_timestamp() { return contents.contains("product_timestamp"); }
59
64 double get_product_timestamp() { return contents["product_timestamp"].get<double>(); }
65
70 void set_product_source(std::string source) { contents["product_source"] = source; }
71
76 bool has_product_source() { return contents.contains("product_source"); }
77
82 std::string get_product_source() { return contents["product_source"].get<std::string>(); }
83
88 void set_product_id(std::string id) { contents["product_id"] = id; }
89
94 bool has_product_id() { return contents.contains("product_id"); }
95
100 std::string get_product_id() { return contents["product_id"].get<std::string>(); }
101
102 public:
103 bool d_use_preset_cache = false;
104
105 public:
111 virtual void save(std::string directory);
112
117 virtual void load(std::string file);
118 };
119
126 std::shared_ptr<Product> loadProduct(std::string path);
127
133 {
134 std::function<std::shared_ptr<Product>(std::string)> loadFromFile;
135 };
136
141 extern std::map<std::string, RegisteredProduct> product_loaders;
142
148 {
149 std::map<std::string, RegisteredProduct> &product_loaders;
150 };
151
157 void registerProducts();
158 } // namespace products
159} // namespace satdump
virtual void save(std::string directory)
Save the product. Depending on the type this will save a product.cbor and other files in the same dir...
Definition product.cpp:16
double get_product_timestamp()
Get the product timestamp.
Definition product.h:64
bool has_product_id()
Check if a product ID is present.
Definition product.h:94
void set_product_source(std::string source)
Set product source, optional. This is meant to contextualize where this product is from,...
Definition product.h:70
void set_product_timestamp(double timestamp)
Set product timestamp, optional. This is usually the rough creation time / acquisition time.
Definition product.h:52
bool has_product_source()
Check if a product source is present.
Definition product.h:76
std::string get_product_id()
Get the product ID.
Definition product.h:100
virtual void load(std::string file)
Load the product. This should refer to the product.cbor file.
Definition product.cpp:28
void set_product_id(std::string id)
Set product ID, optional. This is meant to, for example, differentiate several identical instruments.
Definition product.h:88
std::string get_product_source()
Get the product source.
Definition product.h:82
bool has_product_timestamp()
Check if a product timestamp is present.
Definition product.h:58
Event to subscribe to in plugins to insert new product loaders.
Definition product.h:148
Struct holding functions related to products.
Definition product.h:133