LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
item.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_H
18 #define ITEM_H
19 #include <map>
20 #include <set>
21 #include <iostream>
22 #include "utils/defs.hpp"
23 class engineimp;
24 class retrieve_wrapper;
25 class item;
26 
27 template<class T>
28 void retrieve(T& inval, item* sender, item* caller);
29 class input;
30 class native_item;
31 class item{
32  protected:
33  //_retrieve should never be called by itself, only through the retrieve function
34  //It doesn't really matter whether retrieve is public/private/whatever,
35  //since nothing besides safe_retrieve can construct __retrieve_checkers
36  //Any class overloading this should think carefully about what it's purpose is,
37  //since anything that doesn't hold a native value is likely better off as an item*
38  virtual void _retrieve(retrieve_wrapper&& inval, item* caller);
42  public:
43  item();
44  virtual ~item();
46  static std::shared_ptr<item> create(std::string name, engineimp* rval);
47  virtual void print() const;
48 
49  virtual void postprocess(input& indat);
50  virtual std::vector<std::string> dependencies() const;
51  virtual void update();
52 
53  virtual std::string type() const = 0;
54  void setname(const std::string n);
55  void set_write_name(std::string wname);
56  const std::string& name()const;
57  const std::string& write_name() const;
58 
59  template<class T> friend void retrieve(T& inval, item* setter, item* caller);
60  friend class input;
61  friend class native_item;
62 };
63 class native_item:public item{
64  protected:
65  //move tom protected scope so native values can override it
66  virtual void _retrieve(retrieve_wrapper&& inval, item* caller);
67  public:
68  virtual void parse(const std::string& inval) = 0;
69  std::vector<std::string> dependencies() const;
70  void postprocess(input& inval);
71 };
72 #ifdef ICC
73 
74 bool operator < (const std::weak_ptr<item>& a, std::weak_ptr<item>& b);
75 #endif
76 
77 
78 
79 //classes for testing graphsort, mainly to ensure that it finds cyclical and unsatisfied dependencies
80 class ftest1 : public item{
81  public:
82  virtual std::vector<std::string> dependencies() const{
83  std::string deps[] = {"var1"};
84  return std::vector<std::string>(deps, deps+1);
85  }
86  virtual std::string type() const{
87  return "ftest1";
88  }
89 };
90 
91 class ftest2 : public item{
92  public:
93  virtual std::vector<std::string> dependencies() const{
94  std::string deps[] = {"var2"};
95  return std::vector<std::string>(deps, deps+1);
96  }
97  virtual std::string type() const{
98  return "ftest2";
99  }
100 };
101 class ftest3 : public item{
102  public:
103  virtual std::vector<std::string> dependencies() const{
104  std::string deps[] = {"var3", "var4"};
105  return std::vector<std::string>(deps, deps+2);
106  }
107  virtual std::string type() const{
108  return "ftest3";
109  }
110 };
111 #endif
112