yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stackmap< Key, T, Compare > Struct Template Reference

#include <utils.h>

+ Collaboration diagram for stackmap< Key, T, Compare >:

Public Member Functions

 stackmap ()
 
 stackmap (const std::map< Key, T, Compare > &other)
 
template<typename Other >
void operator= (const Other &other)
 
bool has (const Key &k)
 
void set (const Key &k, const T &v)
 
void unset (const Key &k)
 
const T & get (const Key &k)
 
void reset (const Key &k)
 
const std::map< Key, T, Compare > & stdmap ()
 
void save ()
 
void restore ()
 
 ~stackmap ()
 

Private Attributes

std::vector< std::map< Key, T
*, Compare > > 
backup_state
 
std::map< Key, T, Compare > current_state
 

Static Private Attributes

static T empty_tuple
 

Detailed Description

template<typename Key, typename T, typename Compare = std::less<Key>>
struct stackmap< Key, T, Compare >

Definition at line 35 of file utils.h.

Constructor & Destructor Documentation

template<typename Key, typename T, typename Compare = std::less<Key>>
stackmap< Key, T, Compare >::stackmap ( )
inline

Definition at line 43 of file utils.h.

43 { }
template<typename Key, typename T, typename Compare = std::less<Key>>
stackmap< Key, T, Compare >::stackmap ( const std::map< Key, T, Compare > &  other)
inline

Definition at line 44 of file utils.h.

44 : current_state(other) { }
std::map< Key, T, Compare > current_state
Definition: utils.h:39
template<typename Key, typename T, typename Compare = std::less<Key>>
stackmap< Key, T, Compare >::~stackmap ( )
inline

Definition at line 119 of file utils.h.

120  {
121  while (!backup_state.empty())
122  restore();
123  }
void restore()
Definition: utils.h:107
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38

Member Function Documentation

template<typename Key, typename T, typename Compare = std::less<Key>>
const T& stackmap< Key, T, Compare >::get ( const Key &  k)
inline

Definition at line 77 of file utils.h.

78  {
79  if (current_state.count(k) == 0)
80  return empty_tuple;
81  return current_state.at(k);
82  }
static T empty_tuple
Definition: utils.h:40
std::map< Key, T, Compare > current_state
Definition: utils.h:39
template<typename Key, typename T, typename Compare = std::less<Key>>
bool stackmap< Key, T, Compare >::has ( const Key &  k)
inline

Definition at line 58 of file utils.h.

59  {
60  return current_state.count(k) != 0;
61  }
std::map< Key, T, Compare > current_state
Definition: utils.h:39
template<typename Key, typename T, typename Compare = std::less<Key>>
template<typename Other >
void stackmap< Key, T, Compare >::operator= ( const Other &  other)
inline

Definition at line 47 of file utils.h.

48  {
49  for (auto &it : current_state)
50  if (!backup_state.empty() && backup_state.back().count(it.first) == 0)
51  backup_state.back()[it.first] = new T(it.second);
52  current_state.clear();
53 
54  for (auto &it : other)
55  set(it.first, it.second);
56  }
void set(const Key &k, const T &v)
Definition: utils.h:63
std::map< Key, T, Compare > current_state
Definition: utils.h:39
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38
template<typename Key, typename T, typename Compare = std::less<Key>>
void stackmap< Key, T, Compare >::reset ( const Key &  k)
inline

Definition at line 84 of file utils.h.

85  {
86  for (int i = GetSize(backup_state)-1; i >= 0; i--)
87  if (backup_state[i].count(k) != 0) {
88  if (backup_state[i].at(k) == nullptr)
89  current_state.erase(k);
90  else
91  current_state[k] = *backup_state[i].at(k);
92  return;
93  }
94  current_state.erase(k);
95  }
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
std::map< Key, T, Compare > current_state
Definition: utils.h:39
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38
template<typename Key, typename T, typename Compare = std::less<Key>>
void stackmap< Key, T, Compare >::restore ( )
inline

Definition at line 107 of file utils.h.

108  {
109  log_assert(!backup_state.empty());
110  for (auto &it : backup_state.back())
111  if (it.second != nullptr) {
112  current_state[it.first] = *it.second;
113  delete it.second;
114  } else
115  current_state.erase(it.first);
116  backup_state.pop_back();
117  }
#define log_assert(_assert_expr_)
Definition: log.h:85
std::map< Key, T, Compare > current_state
Definition: utils.h:39
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38

+ Here is the caller graph for this function:

template<typename Key, typename T, typename Compare = std::less<Key>>
void stackmap< Key, T, Compare >::save ( )
inline

Definition at line 102 of file utils.h.

103  {
104  backup_state.resize(backup_state.size()+1);
105  }
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38
template<typename Key, typename T, typename Compare = std::less<Key>>
void stackmap< Key, T, Compare >::set ( const Key &  k,
const T &  v 
)
inline

Definition at line 63 of file utils.h.

64  {
65  if (!backup_state.empty() && backup_state.back().count(k) == 0)
66  backup_state.back()[k] = current_state.count(k) ? new T(current_state.at(k)) : nullptr;
67  current_state[k] = v;
68  }
std::map< Key, T, Compare > current_state
Definition: utils.h:39
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38

+ Here is the caller graph for this function:

template<typename Key, typename T, typename Compare = std::less<Key>>
const std::map<Key, T, Compare>& stackmap< Key, T, Compare >::stdmap ( )
inline

Definition at line 97 of file utils.h.

98  {
99  return current_state;
100  }
std::map< Key, T, Compare > current_state
Definition: utils.h:39
template<typename Key, typename T, typename Compare = std::less<Key>>
void stackmap< Key, T, Compare >::unset ( const Key &  k)
inline

Definition at line 70 of file utils.h.

71  {
72  if (!backup_state.empty() && backup_state.back().count(k) == 0)
73  backup_state.back()[k] = current_state.count(k) ? new T(current_state.at(k)) : nullptr;
74  current_state.erase(k);
75  }
std::map< Key, T, Compare > current_state
Definition: utils.h:39
std::vector< std::map< Key, T *, Compare > > backup_state
Definition: utils.h:38

Field Documentation

template<typename Key, typename T, typename Compare = std::less<Key>>
std::vector<std::map<Key, T*, Compare> > stackmap< Key, T, Compare >::backup_state
private

Definition at line 38 of file utils.h.

template<typename Key, typename T, typename Compare = std::less<Key>>
std::map<Key, T, Compare> stackmap< Key, T, Compare >::current_state
private

Definition at line 39 of file utils.h.

template<typename Key, typename T, typename Compare = std::less<Key>>
T stackmap< Key, T, Compare >::empty_tuple
staticprivate

Definition at line 40 of file utils.h.


The documentation for this struct was generated from the following file: