OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
t_struct_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef T_STRUCT_COMMON_H
6 #define T_STRUCT_COMMON_H
7 
8 #include <algorithm>
9 #include <string>
10 #include <utility>
11 #include <vector>
12 
13 #include "t_type.h"
14 #include "t_field.h"
15 
16 class t_program;
17 
23 class t_struct_common : public t_type {
24  public:
25  typedef std::vector<t_field*> members_type;
26 
27  virtual ~t_struct_common() {}
28 
29  virtual std::string get_struct_type_name() = 0;
30 
32  return members_;
33  }
34 
36  return members_in_id_order_;
37  }
38 
39  bool append(t_field* elem) {
40  members_.push_back(elem);
41 
42  typedef members_type::iterator iter_type;
43  std::pair<iter_type, iter_type> bounds = std::equal_range(
45  elem, t_field::key_compare()
46  );
47 
48  if (bounds.first != bounds.second) {
49  return false;
50  }
51 
52  members_in_id_order_.insert(bounds.second, elem);
53  return true;
54  }
55 
56  virtual std::string get_fingerprint_material() const {
57  std::string rv = "{";
58  members_type::const_iterator m_iter;
59  for (m_iter = members_in_id_order_.begin(); m_iter != members_in_id_order_.end(); ++m_iter) {
60  rv += (*m_iter)->get_fingerprint_material();
61  rv += ";";
62  }
63  rv += "}";
64  return rv;
65  }
66 
67  virtual void generate_fingerprint() {
69  members_type::const_iterator m_iter;
70  for (m_iter = members_in_id_order_.begin(); m_iter != members_in_id_order_.end(); ++m_iter) {
71  (*m_iter)->get_type()->generate_fingerprint();
72  }
73  }
74 
75  protected:
77  t_type(program) {}
78 
79  t_struct_common(t_program* program, const std::string& name) :
80  t_type(program, name) {}
81 
84 };
85 
86 #endif // T_STRUCT_COMMON_H
virtual std::string get_fingerprint_material() const
Definition: t_type.h:48
bool append(t_field *elem)
const members_type & get_sorted_members()
const members_type & get_members()
virtual std::string get_struct_type_name()=0
virtual void generate_fingerprint()
t_struct_common(t_program *program)
members_type members_
virtual void generate_fingerprint()
Definition: parse.cc:13
std::vector< t_field * > members_type
members_type members_in_id_order_
virtual ~t_struct_common()
t_struct_common(t_program *program, const std::string &name)