SASSY  0.0
Software Architecture Support System
 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 SASSY.
7  *
8  * SASSY 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  * SASSY 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 SASSY. 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 SASSY
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 
118 // This macro should be placed at the start of the constructor.
119 #define DISCOVERABLE \
120  SASSY::cfi::DiscoveryMgr::instance().save( __PRETTY_FUNCTION__, \
121  (discover.reset( new SASSY::cfi::DiscoverPointer( this )), discover) );
122 
123 } // namespace cfi
124 } // namespace SASSY
125 
126 #endif /* CFI_DISCOVER_H_ */
A mixin class that makes its owner discoverable.
Definition: discover.h:80
Holds a pointer to a discoverable object.
Definition: discover.h:52
DiscoverSharedPointer discover
A shared pointer that references back to the discoverable object.
Definition: discover.h:84
std::weak_ptr< DiscoverPointer > DiscoverWeakPointer
A weak pointer that will be held by the DiscoveryMgr.
Definition: discover.h:71
static DiscoveryMgr & instance()
Return a reference to the DiscoveryMgr.
Definition: discover.cpp:38
Useful string functions.
DiscoverPointer()
Default constructor.
Definition: discover.h:58
std::shared_ptr< DiscoverPointer > DiscoverSharedPointer
A shared pointer that will be owned by a discoverable object.
Definition: discover.h:68
Manager for discoverable objects.
Definition: discover.h:94
DiscoverPointer(void *a)
Constructor.
Definition: discover.h:64
void * addr
Pointer to a discoverable object.
Definition: discover.h:55
const std::string & csr
Save some time typing and shorten parameter lines.
Definition: stringy.h:35
void fetch(csr name, std::vector< void * > &results)
Get a list of objects with a class name.
Definition: discover.cpp:57
void save(const char *prettyName, DiscoverSharedPointer p)
Save a discoverable object.
Definition: discover.cpp:46