mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 20:05: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
68
src/util/scoped_numeral_buffer.h
Normal file
68
src/util/scoped_numeral_buffer.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*++
|
||||
Copyright (c) 2012 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
scoped_numeral_buffer.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Wrapper for easying the pain when using buffers of numerals.
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2012-01-23
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#ifndef _SCOPED_NUMERAL_BUFFER_H_
|
||||
#define _SCOPED_NUMERAL_BUFFER_H_
|
||||
|
||||
#include"buffer.h"
|
||||
|
||||
template<typename Manager, unsigned INITIAL_SIZE = 16>
|
||||
class _scoped_numeral_buffer : public sbuffer<typename Manager::numeral, INITIAL_SIZE> {
|
||||
typedef sbuffer<typename Manager::numeral, INITIAL_SIZE> super;
|
||||
Manager & m_manager;
|
||||
_scoped_numeral_buffer(_scoped_numeral_buffer const & v);
|
||||
public:
|
||||
_scoped_numeral_buffer(Manager & m):m_manager(m) {}
|
||||
~_scoped_numeral_buffer() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
unsigned sz = this->size();
|
||||
for (unsigned i = 0; i < sz; i++) {
|
||||
m().del(this->operator[](i));
|
||||
}
|
||||
super::reset();
|
||||
}
|
||||
|
||||
Manager & m() const { return m_manager; }
|
||||
|
||||
void push_back(typename Manager::numeral const & v) {
|
||||
super::push_back(typename Manager::numeral());
|
||||
m_manager.set(this->back(), v);
|
||||
}
|
||||
|
||||
void shrink(unsigned sz) {
|
||||
unsigned old_sz = this->size();
|
||||
if (old_sz == sz)
|
||||
return;
|
||||
for (unsigned i = sz; i < old_sz; i++)
|
||||
m().del(this->operator[](i));
|
||||
super::shrink(sz);
|
||||
}
|
||||
|
||||
void resize(unsigned sz) {
|
||||
unsigned old_sz = this->size();
|
||||
if (sz <= old_sz)
|
||||
shrink(sz);
|
||||
typename Manager::numeral zero(0);
|
||||
super::resize(sz, zero);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue