VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
discover.h
Go to the documentation of this file.
1 /*
2  discover.h
3 
4  Copyright 2012 - 2017 Brenton Ross
5 
6 This file is part of VICI.
7 
8 VICI is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 VICI is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with VICI. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
30 #ifndef CFI_DISCOVER_H
31 #define CFI_DISCOVER_H
32 
33 #include "stringy.h"
34 #include <map>
35 #include <vector>
36 #include <memory>
37 
38 namespace VICI
39 {
40 
41 namespace cfi
42 {
43 
45 
53 {
55  void * addr; // reference
56 
58  DiscoverPointer() : addr(nullptr) {}
59 
61 
64  DiscoverPointer(void *a) : addr(a) {}
65 };
66 
68 typedef std::shared_ptr< DiscoverPointer > DiscoverSharedPointer;
69 
71 typedef std::weak_ptr< DiscoverPointer > DiscoverWeakPointer;
72 
74 
81 {
82 protected:
85 };
86 
88 
95 {
96 private:
97  std::map<std::string, std::vector<DiscoverWeakPointer> > objects;
98  DiscoveryMgr() {}
99 public:
101  static DiscoveryMgr & instance();
102 
104 
108  void save(const char *prettyName, DiscoverSharedPointer p);
109 
111 
115  void fetch(csr name, std::vector<void *> & results);
116 };
117 
119 #define DISCOVERABLE \
120  VICI::cfi::DiscoveryMgr::instance().save( __PRETTY_FUNCTION__, \
121  (discover.reset( new VICI::cfi::DiscoverPointer( this )), discover) );
122 
123 } // namespace cfi
124 } // namespace VICI
125 
126 #endif /* CFI_DISCOVER_H_ */
void fetch(csr name, std::vector< void * > &results)
Get a list of objects with a class name.
Definition: discover.cpp:53
A mixin class that makes its owner discoverable.
Definition: discover.h:80
DiscoverPointer()
Default constructor.
Definition: discover.h:58
Useful string functions.
Manager for discoverable objects.
Definition: discover.h:94
static DiscoveryMgr & instance()
Return a reference to the DiscoveryMgr.
Definition: discover.cpp:34
DiscoverSharedPointer discover
A shared pointer that references back to the discoverable object.
Definition: discover.h:84
void save(const char *prettyName, DiscoverSharedPointer p)
Save a discoverable object.
Definition: discover.cpp:42
std::shared_ptr< DiscoverPointer > DiscoverSharedPointer
A shared pointer that will be owned by a discoverable object.
Definition: discover.h:68
std::weak_ptr< DiscoverPointer > DiscoverWeakPointer
A weak pointer that will be held by the DiscoveryMgr.
Definition: discover.h:71
DiscoverPointer(void *a)
Constructor.
Definition: discover.h:64
Holds a pointer to a discoverable object.
Definition: discover.h:52
const std::string & csr
short cut for string constants
Definition: vici.h:80
void * addr
Pointer to a discoverable object.
Definition: discover.h:55