PandA-2024.02
Variable.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
44 #ifndef VARIABLE_HPP
45 #define VARIABLE_HPP
46 
47 #include "custom_map.hpp"
48 #include <iosfwd>
49 
50 #include "graph.hpp"
51 
52 #include "refcount.hpp"
53 
54 #define VARIABLE_COLUMN_SIZE 25
55 
59 template <class data_obj>
60 struct variable2obj : public std::map<unsigned int, data_obj>
61 {
65  variable2obj() = default;
66 
70  virtual ~variable2obj() = default;
71 
76  virtual void print_el(typename variable2obj<data_obj>::const_iterator& it) const = 0;
77 
82  virtual void print() const
83  {
84  auto i_end = this->end();
85  for(auto i = this->begin(); i != i_end; ++i)
86  {
87  print_el(i);
88  }
89  }
90 
91  const data_obj operator()(const unsigned int& __k) const
92  {
93  THROW_ASSERT(this->find(__k) != this->end(), "Impossible to find variable " + std::to_string(__k));
94  return this->find(__k)->second;
95  }
96 
97  template <class Iterator>
98  void resize(Iterator left, Iterator right, int val)
99  {
100  for(; left != right; left++)
101  {
102  this->operator[](*left) = val;
103  }
104  }
105 
110  friend std::ostream& operator<<(std::ostream& os, variable2obj& s)
111  {
112  s.print(os);
113  return os;
114  }
115 
120  friend std::ostream& operator<<(std::ostream& os, const variable2obj* s)
121  {
122  if(s)
123  {
124  s->print(os);
125  }
126  return os;
127  }
128 };
129 
130 #endif
virtual void print_el(typename variable2obj< data_obj >::const_iterator &it) const =0
Function that print the information associated with a variable.
Class specification of the graph structures.
friend std::ostream & operator<<(std::ostream &os, const variable2obj *s)
Friend definition of the << operator.
Definition: Variable.hpp:120
redefinition of map to manage ordered/unordered structures
virtual ~variable2obj()=default
Destructor.
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
variable2obj()=default
Constructor.
Class managing map of the storage values on a generic object.
Definition: Variable.hpp:60
void resize(Iterator left, Iterator right, int val)
Definition: Variable.hpp:98
Template definition of refcount.
virtual void print() const
Function that prints the class variable2obj.
Definition: Variable.hpp:82
friend std::ostream & operator<<(std::ostream &os, variable2obj &s)
Friend definition of the << operator.
Definition: Variable.hpp:110
const data_obj operator()(const unsigned int &__k) const
Definition: Variable.hpp:91
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:53 for PandA-2024.02 by doxygen 1.8.13