LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
item_wrapper.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014, Sam Schetterer, Nathan Kutz, University of Washington
3 Authors: Sam Schetterer
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 
10 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11 
12 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 
16 */
17 #ifndef ITEM_WRAPPER_H
18 #define ITEM_WRAPPER_H
19 #include "item.h"
20 #include <type_traits>
21 class item;
23 /*
24  * This class wraps the items that have been created by the system.
25  * Items need wrapping to have proper dependency resolution. Internally,
26  * all objects are stored in the same map. This means that local objects must have
27  * names that differ from global objects. However, they still must be callable from
28  * the retrieve and dependency functionality and therefore each item must have a local map
29  * from dependency names to actual dependency objects
30  */
32  std::shared_ptr<item> ptr;
33  std::set<std::string> deps;
34  public:
35  template<class T, class = typename std::enable_if<std::is_base_of<item, T>::value>::type>
36  item_wrapper(const std::shared_ptr<T>& inv){
37  ptr = std::static_pointer_cast<item>(inv);
38  if(ptr.use_count()){
39  for(auto& str : inv->dependencies()){
40  deps.insert(str);
41  }
42  }
43  }
44  item_wrapper(const std::shared_ptr<item>& inv);
45  item_wrapper(const item_wrapper& inv);
46  // item_wrapper(item_wrapper&& inv);
47  item_wrapper();
48  std::vector<std::string> dependencies() const;
49  item* get();
50  const item* get() const;
51  item* operator ->();
52  const item* operator ->() const;
53  void add_dep(const std::string& indep);
54  void replace_dep(const std::string& newdep, const std::string& olddep, bool must_rep=true);
55  operator std::shared_ptr<item>();
56  std::shared_ptr<item> get_shared();
57  const std::shared_ptr<item> get_shared()const;
58 
59 };
60 #endif