mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 11:55:51 +00:00
Reorganizing source code. Created util dir
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
630ba0c675
commit
2c464d413d
153 changed files with 0 additions and 0 deletions
55
src/util/scoped_ptr_vector.h
Normal file
55
src/util/scoped_ptr_vector.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*++
|
||||
Copyright (c) 2011 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
scoped_ptr_vector.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Basic template of scoped ptrs.
|
||||
TODO: improve
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo (leonardo) 2011-12-29
|
||||
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
#ifndef _SCOPED_PTR_VECTOR_H_
|
||||
#define _SCOPED_PTR_VECTOR_H_
|
||||
|
||||
#include"vector.h"
|
||||
#include"util.h"
|
||||
|
||||
template<typename T>
|
||||
class scoped_ptr_vector {
|
||||
ptr_vector<T> m_vector;
|
||||
public:
|
||||
~scoped_ptr_vector() { reset(); }
|
||||
void reset() { std::for_each(m_vector.begin(), m_vector.end(), delete_proc<T>()); m_vector.reset(); }
|
||||
void push_back(T * ptr) { m_vector.push_back(ptr); }
|
||||
T * operator[](unsigned idx) const { return m_vector[idx]; }
|
||||
void set(unsigned idx, T * ptr) {
|
||||
if (m_vector[idx] == ptr)
|
||||
return;
|
||||
dealloc(m_vector[idx]);
|
||||
m_vector[idx] = ptr;
|
||||
}
|
||||
unsigned size() const { return m_vector.size(); }
|
||||
bool empty() const { return m_vector.empty(); }
|
||||
void resize(unsigned sz) {
|
||||
if (sz < m_vector.size()) {
|
||||
for (unsigned i = m_vector.size(); i < sz; i++)
|
||||
dealloc(m_vector[i]);
|
||||
m_vector.shrink(sz);
|
||||
}
|
||||
else {
|
||||
for (unsigned i = m_vector.size(); i < sz; i++)
|
||||
push_back(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue