Pothos  0.5.0-ga4964040
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 void save(OStreamArchiver &ar, const void *t) const = 0;
36 
38  virtual void *load(IStreamArchiver &ar) const = 0;
39 
41  static const ArchiveEntry &find(const std::type_info &type);
42 
44  static const ArchiveEntry &find(const std::string &id);
45 
47  static const ArchiveEntry &find(const unsigned long long &hash);
48 
50  const std::string &getId(void) const;
51 
53  const unsigned long long &getHash(void) const;
54 
55 private:
56  const std::string _id;
57  const unsigned long long _hash;
58 };
59 
65 template <typename T>
67 {
68  ArchiveEntryT(const std::string &id);
69 
70  void save(OStreamArchiver &ar, const void *t) const;
71 
72  void *load(IStreamArchiver &ar) const;
73 };
74 
75 } //namespace Archive
76 } //namespace Pothos
77 
78 inline const std::string &Pothos::Archive::ArchiveEntry::getId(void) const
79 {
80  return _id;
81 }
82 
83 inline const unsigned long long &Pothos::Archive::ArchiveEntry::getHash(void) const
84 {
85  return _hash;
86 }
87 
88 template <typename T>
90  ArchiveEntry(typeid(T), id)
91 {
92  return;
93 }
94 
95 template <typename T>
97 {
98  ar << (*static_cast<const T *>(t));
99 }
100 
101 template <typename T>
103 {
104  T *t = new T();
105  ar >> *t;
106  return t;
107 }
const std::string & getId(void) const
Get the associated unique ID.
Definition: ArchiveEntry.hpp:78
void * load(IStreamArchiver &ar) const
Load a pointer from the archive in a derived class.
Definition: ArchiveEntry.hpp:102
const unsigned long long & getHash(void) const
Get a reproducible hash for this entry.
Definition: ArchiveEntry.hpp:83
#define POTHOS_API
Definition: Config.hpp:41
Definition: ArchiveEntry.hpp:66
ArchiveEntryT(const std::string &id)
Definition: ArchiveEntry.hpp:89
Definition: ArchiveEntry.hpp:20
Definition: StreamArchiver.hpp:47
void save(Archive &ar, const std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:20
void save(OStreamArchiver &ar, const void *t) const
Save a pointer to the archive in a derived class.
Definition: ArchiveEntry.hpp:96
Definition: ArchiveEntry.hpp:27
Definition: StreamArchiver.hpp:23
void load(Archive &ar, std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:27