OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Model Class Reference

#include <Model.hh>

Collaboration diagram for Model:
Collaboration graph

Public Member Functions

 Model ()
 
 Model (const std::string &fileName)
 
 ~Model ()
 
TTAMachine::MachinegetMachine ()
 
void undo ()
 
void redo ()
 
bool canUndo ()
 
bool canRedo ()
 
void addObserver (ModelObserver *observer)
 
void notifyObservers (bool modified=true)
 
void pushToStack ()
 
void popFromStack (bool modified=false)
 
void setNotModified ()
 
bool isModified () const
 

Private Types

typedef std::vector< ModelObserver * > ObserverTable
 Table of model observers.
 
typedef std::deque< TTAMachine::Machine * > UndoStack
 Machine stack for undo functionality.
 

Private Member Functions

 Model (const Model &)
 Copying not allowed.
 
Modeloperator= (const Model &)
 Assignment not allowed.
 

Private Attributes

TTAMachine::Machinemachine_
 Machine assigned for this Model. Singleton within a Model.
 
ObserverTable observers_
 Model observers.
 
unsigned undoStackSize_
 Maximum size of the undo stack.
 
UndoStack undoStack_
 
TTAMachine::Machineundone_
 Undone modification cache for the redo funciton.
 
bool modified_
 

Static Private Attributes

static const unsigned int UNDO_STACK_MAX_SIZE
 Maximum undo stack size.
 

Detailed Description

An interface for modifying the Machine Object Model.

Definition at line 50 of file Model.hh.

Member Typedef Documentation

◆ ObserverTable

typedef std::vector<ModelObserver*> Model::ObserverTable
private

Table of model observers.

Definition at line 76 of file Model.hh.

◆ UndoStack

typedef std::deque<TTAMachine::Machine*> Model::UndoStack
private

Machine stack for undo functionality.

Definition at line 89 of file Model.hh.

Constructor & Destructor Documentation

◆ Model() [1/3]

Model::Model ( )

The Constructor.

Definition at line 53 of file Model.cc.

53 : machine_(new Machine()), undone_(NULL), modified_(false) {
54}
bool modified_
Definition Model.hh:94
TTAMachine::Machine * machine_
Machine assigned for this Model. Singleton within a Model.
Definition Model.hh:73
TTAMachine::Machine * undone_
Undone modification cache for the redo funciton.
Definition Model.hh:92

◆ Model() [2/3]

Model::Model ( const std::string &  fileName)

The Constructor.

Creates model from a specified file.

Parameters
fileNameThe file name of the machine description to open.

Definition at line 77 of file Model.cc.

77 : undone_(NULL), modified_(false) {
78 // read Machine from fileName and set it to machine_
79 ADFSerializer reader;
80 reader.setSourceFile(fileName);
81 machine_ = reader.readMachine();
82}
TTAMachine::Machine * readMachine()
void setSourceFile(const std::string &fileName)

References machine_, ADFSerializer::readMachine(), and XMLSerializer::setSourceFile().

Here is the call graph for this function:

◆ ~Model()

Model::~Model ( )

The Destructor.

Definition at line 60 of file Model.cc.

60 {
61 // delete machine object states in the undo stack
62 while (undoStack_.size() != 0) {
63 Machine* machine = undoStack_.front();
64 undoStack_.pop_front();
65 delete machine;
66 }
67}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
UndoStack undoStack_
Definition Model.hh:90

References machine, and undoStack_.

◆ Model() [3/3]

Model::Model ( const Model )
private

Copying not allowed.

Member Function Documentation

◆ addObserver()

void Model::addObserver ( ModelObserver observer)

Adds an observer for this Model.

Parameters
observerThe observer to add.

Definition at line 143 of file Model.cc.

143 {
144 observers_.push_back(observer);
145}
ObserverTable observers_
Model observers.
Definition Model.hh:79

References observers_.

Referenced by MDFDocument::OnNewDocument(), and MDFDocument::openADF().

◆ canRedo()

bool Model::canRedo ( )

Returns true if the last undone command can be redone.

Returns
True, if the last undone command can be redone.

Definition at line 228 of file Model.cc.

228 {
229 if (undone_ != NULL) {
230 return true;
231 }
232 return false;
233}

References undone_.

Referenced by RedoCmd::isEnabled().

◆ canUndo()

bool Model::canUndo ( )

Returns true if the undo stack is not empty.

Returns
True, if the undo stack is not empty.

Definition at line 213 of file Model.cc.

213 {
214 if (undoStack_.size() > 0) {
215 return true;
216 }
217 return false;
218}

References undoStack_.

Referenced by UndoCmd::isEnabled().

◆ getMachine()

Machine * Model::getMachine ( )

◆ isModified()

bool Model::isModified ( ) const
inline

Definition at line 66 of file Model.hh.

66{ return modified_; }

References modified_.

Referenced by MDFDocument::update().

◆ notifyObservers()

void Model::notifyObservers ( bool  modified = true)

◆ operator=()

Model & Model::operator= ( const Model )
private

Assignment not allowed.

◆ popFromStack()

void Model::popFromStack ( bool  modified = false)

Replaces the current machine with the one that is in the top of the undo stack.

Definition at line 195 of file Model.cc.

195 {
196
197 if (machine_ != NULL) {
198 delete machine_;
199 }
200
201 machine_ = undoStack_.front();
202 undoStack_.pop_front();
203 notifyObservers(modified);
204}
void notifyObservers(bool modified=true)
Definition Model.cc:152

References machine_, notifyObservers(), and undoStack_.

Referenced by AddASCmd::Do(), AddBridgeCmd::Do(), AddBusCmd::Do(), AddFUCmd::Do(), AddGCUCmd::Do(), AddIUCmd::Do(), AddRFCmd::Do(), AddSocketCmd::Do(), BlocksConnectICCmd::Do(), CallExplorerPluginCmd::Do(), DeleteComponentCmd::Do(), EditAddressSpacesCmd::Do(), EditBusOrderCmd::Do(), EditImmediateSlotsCmd::Do(), EditMachineCmd::Do(), EditOTAFormatsCmd::Do(), EditTemplatesCmd::Do(), ModifyComponentCmd::Do(), PasteComponentCmd::Do(), VLIWConnectICCmd::Do(), ConnectTool::leftClick(), and undo().

Here is the call graph for this function:

◆ pushToStack()

void Model::pushToStack ( )

Pushes the current machine to the undo stack.

Definition at line 167 of file Model.cc.

167 {
168
169 // Redo is not available after modifications, clear redo cache
170 if (undone_ != NULL) {
171 delete undone_;
172 undone_ = NULL;
173 }
174
175 // if undo stack size is at maximum, delete oldest machine from the stack
176 while (undoStack_.size() > 0 &&
177 undoStack_.size() >=
178 unsigned(wxGetApp().options()->undoStackSize())) {
179
180 Machine* last = undoStack_.back();
181 undoStack_.pop_back();
182 delete last;
183 }
184
185 // push copy of the current machine to the undo stack
186 undoStack_.push_front(new Machine(*machine_));
187}
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46

References machine_, options, undone_, and undoStack_.

Referenced by AddASCmd::Do(), AddBridgeCmd::Do(), AddBusCmd::Do(), AddFUCmd::Do(), AddGCUCmd::Do(), AddIUCmd::Do(), AddRFCmd::Do(), AddSocketCmd::Do(), BlocksConnectICCmd::Do(), CallExplorerPluginCmd::Do(), CutComponentCmd::Do(), DeleteComponentCmd::Do(), EditAddressSpacesCmd::Do(), EditBusOrderCmd::Do(), EditImmediateSlotsCmd::Do(), EditMachineCmd::Do(), EditOTAFormatsCmd::Do(), EditTemplatesCmd::Do(), FullyConnectBussesCmd::Do(), ModifyComponentCmd::Do(), PasteComponentCmd::Do(), VLIWConnectICCmd::Do(), ConnectTool::leftClick(), AddFUFromHDBDialog::onAdd(), AddIUFromHDBDialog::onAdd(), AddRFFromHDBDialog::onAdd(), and redo().

◆ redo()

void Model::redo ( )

Redoes last undoed modification.

Definition at line 118 of file Model.cc.

118 {
119
120 assert (undone_ != NULL);
121
122 Machine* undone = undone_;
123 undone_ = NULL;
124
125 // push machine to the undo stack before redoing
126 pushToStack();
127
128 // replace machine from the redo cache
129 if (machine_ != NULL) {
130 delete machine_;
131 }
132
133 machine_ = undone;
135}
#define assert(condition)
void pushToStack()
Definition Model.cc:167

References assert, machine_, notifyObservers(), pushToStack(), and undone_.

Here is the call graph for this function:

◆ setNotModified()

void Model::setNotModified ( )
inline

Definition at line 65 of file Model.hh.

65{ modified_ = false; }

References modified_.

Referenced by MDFDocument::update().

◆ undo()

void Model::undo ( )

Restores Machine to the state before the last modification.

Definition at line 97 of file Model.cc.

97 {
98
99 // delete redo cache
100 if (undone_ != NULL) {
101 delete undone_;
102 undone_ = NULL;
103 }
104
105 // add machine to the redo cache before undo
106 undone_ = new Machine(*machine_);
107
108 // pop last machine from the undo stack and set is as the machine
109 // and set machine as modified.
110 popFromStack(true);
111}
void popFromStack(bool modified=false)
Definition Model.cc:195

References machine_, popFromStack(), and undone_.

Here is the call graph for this function:

Member Data Documentation

◆ machine_

TTAMachine::Machine* Model::machine_
private

Machine assigned for this Model. Singleton within a Model.

Definition at line 73 of file Model.hh.

Referenced by getMachine(), Model(), popFromStack(), pushToStack(), redo(), and undo().

◆ modified_

bool Model::modified_
private

Definition at line 94 of file Model.hh.

Referenced by isModified(), notifyObservers(), and setNotModified().

◆ observers_

ObserverTable Model::observers_
private

Model observers.

Definition at line 79 of file Model.hh.

Referenced by addObserver(), and notifyObservers().

◆ UNDO_STACK_MAX_SIZE

const unsigned int Model::UNDO_STACK_MAX_SIZE
staticprivate

Maximum undo stack size.

Definition at line 70 of file Model.hh.

◆ undone_

TTAMachine::Machine* Model::undone_
private

Undone modification cache for the redo funciton.

Definition at line 92 of file Model.hh.

Referenced by canRedo(), pushToStack(), redo(), and undo().

◆ undoStack_

UndoStack Model::undoStack_
private

Definition at line 90 of file Model.hh.

Referenced by canUndo(), popFromStack(), pushToStack(), and ~Model().

◆ undoStackSize_

unsigned Model::undoStackSize_
private

Maximum size of the undo stack.

Definition at line 87 of file Model.hh.


The documentation for this class was generated from the following files: