|
TuringSim
C++ framework to simulate abstract computing models
|
3 #include <utils/messageException.h>
42 std::ostringstream ss;
43 ss << this->
msg << std::endl;
44 ss <<
" size factor: " <<
sizeFactor << std::endl;
56 template<
typename Memory,
typename Modifier>
88 std::ostringstream ss;
89 ss << this->
msg << std::endl;
90 ss <<
" memory structure address: " <<
memory << std::endl;
91 ss <<
" existing modifier address: " <<
modifier << std::endl;
98 template <
typename D,
typename O>
100 template <
typename D,
typename M>
116 template <
typename T,
typename D,
typename O,
typename M>
140 for(
Observer* observer: observers) {
141 observer->unsafe_release();
144 (*modifier)->unsafe_release();
168 mutable std::set<Observer*> observers;
174 mutable std::optional<Modifier*> modifier;
186 template <
typename Memory,
typename Observer>
258 if(toAcquire !=
nullptr) {
260 memory->observers.insert(
static_cast<Observer*
>(
this));
269 memory->observers.erase(
static_cast<Observer*
>(
this));
306 template <
typename Memory,
typename Modifier>
329 Memory* otherMemory = other->memory;
344 Memory* otherMemory = other->
memory;
370 if(toAcquire->modifier) {
374 if(toAcquire !=
nullptr) {
376 memory->modifier =
static_cast<Modifier*
>(
this);
391 if(toAcquire !=
nullptr) {
392 if (toAcquire->modifier) {
393 (*toAcquire->modifier)->
release();
396 memory->modifier =
static_cast<Modifier*
>(
this);
void unsafe_release()
Releases the current observed memory, without checking if there is some.
MessageException()=delete
a message exception must have an explicative message.
const Modifier * getModifier() const
Access the existing modifier.
size_t sizeFactor
The illegal factor.
MemoryModifier & operator=(MemoryModifier &&other)
Move assignment operator.
const std::set< Observer * > & getObservers() const noexcept
Gets the set of observers.
MemoryObserver & operator=(MemoryObserver &&other)
Move assignment operator.
std::string msg
The error message.
size_t getIllegalSizeFactor() const noexcept
Return the illegal factor.
friend Modifier
Modifier class.
The Base class for all custom exceptions.
const Memory * getMemory() const
Access the memory structure.
MemoryModifier()
Default constructor that binds no memory structure.
friend Observer
Observer class.
virtual std::string makeFullMessage() const override
Build the full error message. It should be overridden by derived class that adds data to the exceptio...
void acquire(const Memory *toAcquire)
Observe a new memory structure.
Exception thrown when a size factor is set to an illegal value.
~MemoryObserver()
Destruct an observer and release the memory structure.
Namespace for all component of the framework.
MemoryObserver & operator=(MemoryObserver &other)
Copy assignment operator.
T SymbolType
The alphabet type.
MemoryModifier(const MemoryModifier &other)=delete
Copy constructor is deleted because a memory structure should have only one modifier.
void acquire(Memory *toAcquire)
Bind a new memory structure.
Memory * memory
The observed memory.
void release()
Releases the current bounded memory if there is one. Otherwise, does nothing.
const Memory * memory
The observed memory.
bool empty() const noexcept
Check if *this observes a memory.
const std::optional< Modifier * > & getModifier() const noexcept
Gets the optional modifier.
void unsafe_release()
Releases the current observed memory, without checking if there is some.
Base class for all memory structures.
InvalidFactorException(std::string message, size_t sizeFactor)
Build an InvalidFactorException from an error message and an offending size factor.
ExistingModifierException(std::string message, const Memory *memory, const Modifier *modifier)
Build an ExistingModifierException from an error message, a pointer to the memory structure,...
~MemoryModifier()
Destruct a modifier and release the memory structure.
MemoryModifier(MemoryModifier &&other)
Move constructor.
MemoryObserver(MemoryObserver &&other)
Move constructor.
MemoryObserver(const MemoryObserver &other)
Build a new observer to the same memory.
InvalidFactorException()=delete
An InvalidFactorException must contain an error message and the offending size factor.
const Memory * memory
The involved memory structure.
O Observer
The type of observers.
MemoryObserver(const Memory *memory)
Build an observer that observes a given memory.
void release()
Releases the current observed memory if there is one. Otherwise, does nothing.
Exception thrown when attempting to bound a modifier to a memory structure that is already bound to a...
const Modifier * modifier
The other modifier.
virtual std::string makeFullMessage() const override
Build the full error message. It should be overridden by derived class that adds data to the exceptio...
MemoryModifier & operator=(MemoryModifier &)=delete
Copy assignment operator is deleted because a memory structure should have only one modifier.
Base class for all memory observers.
MemoryModifier(Memory *m)
Constructor that binds to a memory structure.
Base class for all memory modifiers.
ExistingModifierException()=delete
An ExistingModifierException must contain an error message, a pointer to the memory structure,...
Memory structures used by machines, such as tapes, stacks...
~MemoryStructure()
Release current observers and modifier.
MemoryObserver() noexcept
Build an observer that observes nothing.
bool empty() const noexcept
Check if *this is bounded to a memory.
M Modifier
The type of modifiers.
void force_acquire(Memory *toAcquire)
Bind a new memory structure.