Pothos  0.7.0-gf7fbae99
The Pothos dataflow programming software suite
ArchiveEntry.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #include <Pothos/Config.hpp>
15 #include <type_traits>
16 #include <typeinfo>
17 #include <iosfwd>
18 #include <string>
19 
20 namespace Pothos {
21 namespace Archive {
22 
28 {
29 public:
30 
32  ArchiveEntry(const std::type_info &type, const std::string &id);
33 
35  virtual ~ArchiveEntry(void);
36 
38  virtual void save(OStreamArchiver &ar, const void *t) const = 0;
39 
41  virtual void *load(IStreamArchiver &ar) const = 0;
42 
44  static const ArchiveEntry &find(const std::type_info &type);
45 
47  static const ArchiveEntry &find(const std::string &id);
48 
50  static const ArchiveEntry &find(const unsigned long long &hash);
51 
53  const std::string &getId(void) const;
54 
56  const unsigned long long &getHash(void) const;
57 
58 private:
59  const std::string _id;
60  const unsigned long long _hash;
61 };
62 
68 template <typename T>
70 {
71  ArchiveEntryT(const std::string &id);
72 
73  void save(OStreamArchiver &ar, const void *t) const;
74 
75  void *load(IStreamArchiver &ar) const;
76 };
77 
78 } //namespace Archive
79 } //namespace Pothos
80 
81 inline const std::string &Pothos::Archive::ArchiveEntry::getId(void) const
82 {
83  return _id;
84 }
85 
86 inline const unsigned long long &Pothos::Archive::ArchiveEntry::getHash(void) const
87 {
88  return _hash;
89 }
90 
91 template <typename T>
93  ArchiveEntry(typeid(T), id)
94 {
95  return;
96 }
97 
98 template <typename T>
100 {
101  ar << (*static_cast<const T *>(t));
102 }
103 
104 template <typename T>
106 {
107  T *t = new T();
108  ar >> *t;
109  return t;
110 }
#define POTHOS_API
Definition: Config.hpp:41
Definition: ArchiveEntry.hpp:69
const unsigned long long & getHash(void) const
Get a reproducible hash for this entry.
Definition: ArchiveEntry.hpp:86
ArchiveEntryT(const std::string &id)
Definition: ArchiveEntry.hpp:92
void * load(IStreamArchiver &ar) const
Load a pointer from the archive in a derived class.
Definition: ArchiveEntry.hpp:105
Definition: ArchiveEntry.hpp:20
Definition: StreamArchiver.hpp:63
void save(Archive &ar, const std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:20
const std::string & getId(void) const
Get the associated unique ID.
Definition: ArchiveEntry.hpp:81
Definition: ArchiveEntry.hpp:27
Definition: StreamArchiver.hpp:23
void save(OStreamArchiver &ar, const void *t) const
Save a pointer to the archive in a derived class.
Definition: ArchiveEntry.hpp:99
void load(Archive &ar, std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:27