PandA-2024.02
Vertex.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 VERTEX_HPP
45 #define VERTEX_HPP
46 
47 #include "custom_map.hpp"
48 #include <iosfwd>
49 
50 #include "graph.hpp"
51 #include "typed_node_info.hpp"
52 
53 #define COLUMN_SIZE 30
54 
58 template <class data_obj>
59 struct vertex2obj : public CustomUnorderedMapUnstable<vertex, data_obj>
60 {
64  vertex2obj() = default;
65 
69  virtual ~vertex2obj() = default;
70 
75  virtual void print_el(std::ostream& os, const graph*, typename vertex2obj<data_obj>::const_iterator& it) const
76  {
77  os << "(" << it->second << ") ";
78  }
79 
84  virtual void print_rowHead(std::ostream& os, const graph* data,
85  typename vertex2obj<data_obj>::const_iterator& it) const
86  {
87  if(data)
88  {
89  os << "Operation: ";
90  os.width(COLUMN_SIZE);
91  os.setf(std::ios_base::left, std::ios_base::adjustfield);
93  os.width(0);
94  }
95  else
96  {
97  os << it->first;
98  }
99  }
104  virtual void print(std::ostream& os, const graph* data = nullptr) const
105  {
106  auto i_end = this->end();
107  for(auto i = this->begin(); i != i_end; ++i)
108  {
109  print_rowHead(os, data, i);
110  print_el(os, data, i);
111  if(data)
112  {
113  os << std::endl;
114  }
115  else
116  {
117  os << " ";
118  }
119  }
120  if(!data)
121  {
122  os << std::endl;
123  }
124  }
125 
126  const data_obj operator()(const vertex& __k) const
127  {
128  THROW_ASSERT(this->find(__k) != this->end(), "expected a meaningful vertex");
129  return this->find(__k)->second;
130  }
131  template <class Iterator, class data_type>
132  void resize(Iterator left, Iterator right, data_type val)
133  {
134  for(; left != right; left++)
135  {
136  this->operator[](*left) = val;
137  }
138  }
139 
144  friend std::ostream& operator<<(std::ostream& os, const vertex2obj& s)
145  {
146  s.print(os);
147  return os;
148  }
149 
154  friend std::ostream& operator<<(std::ostream& os, const vertex2obj* s)
155  {
156  if(s)
157  {
158  s->print(os);
159  }
160  return os;
161  }
162 };
163 
164 struct vertex2int : public vertex2obj<int>
165 {
166 };
167 
168 struct vertex2float : public vertex2obj<double>
169 {
170 };
171 
172 #endif
friend std::ostream & operator<<(std::ostream &os, const vertex2obj *s)
Friend definition of the << operator.
Definition: Vertex.hpp:154
virtual ~vertex2obj()=default
Destructor.
virtual void print(std::ostream &os, const graph *data=nullptr) const
Function that prints the class vertex2obj.
Definition: Vertex.hpp:104
#define COLUMN_SIZE
Definition: Vertex.hpp:53
Class specification of the graph structures.
Class managing map of the vertexes on a generic object.
Definition: Vertex.hpp:59
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapUnstable
Definition: custom_map.hpp:156
Base class description of data information associated with each node of a graph.
redefinition of map to manage ordered/unordered structures
const data_obj operator()(const vertex &__k) const
Definition: Vertex.hpp:126
friend std::ostream & operator<<(std::ostream &os, const vertex2obj &s)
Friend definition of the << operator.
Definition: Vertex.hpp:144
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
void resize(Iterator left, Iterator right, data_type val)
Definition: Vertex.hpp:132
virtual void print_rowHead(std::ostream &os, const graph *data, typename vertex2obj< data_obj >::const_iterator &it) const
Function that print the name and the operation performed by the vertex.
Definition: Vertex.hpp:84
General class used to describe a graph in PandA.
Definition: graph.hpp:771
virtual void print_el(std::ostream &os, const graph *, typename vertex2obj< data_obj >::const_iterator &it) const
Function that print the information associated with a vertex.
Definition: Vertex.hpp:75
vertex2obj()=default
Constructor.
#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