LILAC
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
item_dim.cpp
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 #include "item_dim.h"
18 #include "utils/item_heads.hpp"
19 void item_dim::_do_mem_update(size_t dim_old){
21 }
22 /*
23  * Postprocesses the item_dim class, which sets the dimension to the input variable dimension
24  */
26  int dimt;
27  parent=0;
28  dat.retrieve(dimt, "dimension", this);
29  if(dimt <= 0){
30  std::string errmess = "dimension invalid, must be >= 0";
31  err(errmess, "int_dim::postprocess", "item/item.cpp",
32  dat["dimension"], FATAL_ERROR);
33  }
34  dimension = (size_t)dimt;
35 }
36 
43 std::vector<std::string> item_dim::dependencies()const{
44  std::vector<std::string> de;
45  de.push_back("dimension");
46  return de;
47 }
48 
49 
51  if(parent){
52  err(this->name() + " is already a child of " +
53  parent->name() + ", not adding as a child of " +
54  p->name(), "item_dim::add_as_parent", "engine/item_dim.cpp",
55  WARNING);
56  }
57  else{
58  p->children.insert(this);
59  parent=p;
60  if(dimension != p->dimension){
62  err(std::string() + "Changing dimension of "+ name() + " to match " + p->name(),
63  "item_dim::add_as_parent", "engine/item_dim.cpp", WARNING);
64  }
65  }
66 }
67 
68 void item_dim::add_as_parent(std::shared_ptr<item_dim> p){
69  add_as_parent(p.get());
70 }
71 
72 
73 void item_dim::update_dim(size_t dim_new){
74  if(parent){
75  err(std::string("Item_dim* ") + this->name() + " is not the head of the \
76  dimension dependency tree", "item_dim::update_dim(size_t)",
77  "engine/item_dim.cpp", WARNING);
79  }
80  else{
81  update_dim(dim_new, 0);
82  }
83 }
84 void item_dim::update_dim(size_t dim_new, size_t dummy){
85  size_t dim_old = dimension;
86  dimension = dim_new;
87  _do_mem_update(dim_old);
88  for(auto child : children){
89  child->update_dim(dim_new, dummy);
90  }
91 }
93  std::cout << this->name();
94  if(parent){
95  std::cout << " -> ";
97  }
98  else{
99  std::cout << std::endl;
100  }
101 }