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

#include <FindWindow.hh>

Inheritance diagram for FindWindow:
Inheritance graph
Collaboration diagram for FindWindow:
Collaboration graph

Public Member Functions

 FindWindow (ProximMainFrame *parent, int id)
 
virtual ~FindWindow ()
 
virtual void reset ()
 

Private Types

enum  {
  ID_OP_INPUT , ID_MATCH_CASE , ID_INFO_LABEL , ID_FIND_PREV ,
  ID_FIND_NEXT
}
 Widget IDs. More...
 

Private Member Functions

void onInputText (wxCommandEvent &event)
 
void onFindPrev (wxCommandEvent &event)
 
void onFindNext (wxCommandEvent &event)
 
bool find (std::string searchString)
 
wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 

Private Attributes

wxTextCtrl * opInput_
 
wxCheckBox * matchCase_
 
wxStaticText * infoLabel_
 
wxButton * findPrevBtn_
 
wxButton * findNextBtn_
 
std::vector< int > matchedLines
 List of code linenumbers where serached text was found.
 
int matchedIndex
 Currently displayed codeline index in matchedLines.
 

Additional Inherited Members

- Protected Member Functions inherited from ProximSimulatorWindow
 ProximSimulatorWindow (ProximMainFrame *mainFrame, wxWindowID id=-1, wxPoint pos=wxDefaultPosition, wxSize size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
 
virtual ~ProximSimulatorWindow ()
 

Detailed Description

Window for searching text patterns in disassembly instructions.

Definition at line 49 of file FindWindow.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Widget IDs.

Enumerator
ID_OP_INPUT 
ID_MATCH_CASE 
ID_INFO_LABEL 
ID_FIND_PREV 
ID_FIND_NEXT 

Definition at line 75 of file FindWindow.hh.

Constructor & Destructor Documentation

◆ FindWindow()

FindWindow::FindWindow ( ProximMainFrame parent,
int  id 
)

Definition at line 57 of file FindWindow.cc.

57 :
58 ProximSimulatorWindow(parent, id) {
59
60 createContents(this, true, true);
61 opInput_->SetFocus();
62 matchCase_->SetValue(false);
63 findPrevBtn_->Disable();
64 findNextBtn_->Disable();
65}
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxTextCtrl * opInput_
Definition FindWindow.hh:63
wxButton * findNextBtn_
Definition FindWindow.hh:67
wxButton * findPrevBtn_
Definition FindWindow.hh:66
wxCheckBox * matchCase_
Definition FindWindow.hh:64

◆ ~FindWindow()

FindWindow::~FindWindow ( )
virtual

Definition at line 68 of file FindWindow.cc.

68 {
69}

Member Function Documentation

◆ createContents()

wxSizer * FindWindow::createContents ( wxWindow *  parent,
bool  call_fit,
bool  set_sizer 
)
private

Creates the dialog widgets.

Definition at line 211 of file FindWindow.cc.

212 {
213
214 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
215 wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
216
217 opInput_ = new wxTextCtrl(parent, ID_OP_INPUT, wxT(""),
218 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
219 mainSizer->Add(opInput_, 0, wxALL|wxEXPAND, 5);
220
221 matchCase_ = new wxCheckBox(parent, ID_MATCH_CASE, wxT("Case sensitive"),
222 wxDefaultPosition, wxDefaultSize);
223 mainSizer->Add(matchCase_, 0, wxALL|wxEXPAND, 5);
224
225 infoLabel_ = new wxStaticText(parent, ID_INFO_LABEL, wxT(""),
226 wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
227 mainSizer->Add(infoLabel_, 0, wxALL|wxEXPAND, 5);
228
229 findPrevBtn_ = new wxButton(parent, ID_FIND_PREV, wxT("Previous"),
230 wxDefaultPosition, wxDefaultSize, 0);
231 findNextBtn_ = new wxButton(parent, ID_FIND_NEXT, wxT("Find next"),
232 wxDefaultPosition, wxDefaultSize, 0);
233
234 buttonSizer->Add(findPrevBtn_, 0, wxALL, 5);
235 buttonSizer->Add(findNextBtn_, 0, wxALL, 5);
236
237 mainSizer->Add(buttonSizer, 0, wxALIGN_CENTER|wxALL, 5);
238
239 if (set_sizer) {
240 parent->SetSizer(mainSizer);
241 if (call_fit) {
242 mainSizer->SetSizeHints(parent);
243 }
244 }
245
246 return mainSizer;
247}
wxStaticText * infoLabel_
Definition FindWindow.hh:65

References findNextBtn_, findPrevBtn_, ID_FIND_NEXT, ID_FIND_PREV, ID_INFO_LABEL, ID_MATCH_CASE, ID_OP_INPUT, infoLabel_, matchCase_, and opInput_.

◆ find()

bool FindWindow::find ( std::string  searchString)
private

Definition at line 169 of file FindWindow.cc.

169 {
170
172 std::size_t found;
173 matchedIndex = 0;
174 matchedLines.clear();
175
176 for (int i = 0; i < program.instructionCount(); i++) {
177 const TTAProgram::Instruction& instruction = program.instructionAt(i);
178
179 std::string instrString = "";
180
181 for (int j = 0; j < instruction.moveCount(); j++) {
182 const TTAProgram::Move& move = instruction.move(j);
183 instrString += move.toString();
184 }
185 // remove spaces in instruction and search pattern
186 instrString.erase(remove_if(instrString.begin(), instrString.end(),
187 isspace), instrString.end());
188 pattern.erase(remove_if(pattern.begin(), pattern.end(),
189 isspace), pattern.end());
190 // case insensitive search
191 if (!matchCase_->IsChecked()) {
192 std::transform(instrString.begin(), instrString.end(),
193 instrString.begin(), ::tolower);
194 std::transform(pattern.begin(), pattern.end(), pattern.begin(),
195 ::tolower);
196 }
197
198 found = instrString.find(pattern);
199 if (found != std::string::npos) {
200 matchedLines.push_back(i);
201 }
202 }
203 return matchedLines.size() > 0;
204}
find Finds info of the inner loops in the program
int matchedIndex
Currently displayed codeline index in matchedLines.
Definition FindWindow.hh:72
std::vector< int > matchedLines
List of code linenumbers where serached text was found.
Definition FindWindow.hh:70
static const TTAProgram::Program & program()
Move & move(int i) const
std::string toString() const
Definition Move.cc:436

References matchCase_, matchedIndex, matchedLines, TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), program, ProximToolbox::program(), and TTAProgram::Move::toString().

Referenced by onInputText().

Here is the call graph for this function:

◆ onFindNext()

void FindWindow::onFindNext ( wxCommandEvent &  event)
private

Definition at line 142 of file FindWindow.cc.

142 {
143
144 int matchedSize = matchedLines.size();
145 if (matchedSize == 0) {
146 return;
147 }
148
149 if (matchedIndex == matchedSize - 1) {
150 matchedIndex = 0;
151 } else {
152 matchedIndex++;
153 }
154 // update label
155 infoLabel_->SetLabel(WxConversion::toWxString(matchedIndex+1) + wxT(" of ") +
156 WxConversion::toWxString(matchedSize) + wxT(" matched lines"));
157
159}
void showAddress(unsigned address)
static ProximDisassemblyWindow * disassemblyWindow()
static wxString toWxString(const std::string &source)

References ProximToolbox::disassemblyWindow(), infoLabel_, matchedIndex, matchedLines, ProximDisassemblyWindow::showAddress(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ onFindPrev()

void FindWindow::onFindPrev ( wxCommandEvent &  event)
private

Definition at line 120 of file FindWindow.cc.

120 {
121
122 int matchedSize = matchedLines.size();
123 if (matchedSize == 0) {
124 return;
125 }
126
127 if (matchedIndex == 0) {
128 matchedIndex = matchedSize - 1;
129 } else {
130 matchedIndex--;
131 }
132 infoLabel_->SetLabel(WxConversion::toWxString(matchedIndex+1) + wxT(" of ") +
133 WxConversion::toWxString(matchedSize) + wxT(" matched lines"));
135}

References ProximToolbox::disassemblyWindow(), infoLabel_, matchedIndex, matchedLines, ProximDisassemblyWindow::showAddress(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ onInputText()

void FindWindow::onInputText ( wxCommandEvent &  event)
private

Called when the input text changes or match case checkbox changes state.

Definition at line 84 of file FindWindow.cc.

84 {
85 wxString inputwxString = opInput_->GetValue();
86
87 if (inputwxString.Length() > 2) {
88 std::string pattern = WxConversion::toString(inputwxString);
89
90 bool found = find(pattern);
91 if (found) {
92 findPrevBtn_->Enable();
93 findNextBtn_->Enable();
94
95 int total = matchedLines.size();
96 // update label
97 infoLabel_->SetLabel(wxT("1 of ") + WxConversion::toWxString(total)+
98 wxT(" matched lines"));
99 // jump to first matched line
101
102 return;
103
104 } else {
105 infoLabel_->SetLabel(wxT("Pattern not found"));
106 return;
107 }
108
109 }
110 infoLabel_->SetLabel(wxT(""));
111 findPrevBtn_->Disable();
112 findNextBtn_->Disable();
113}
bool find(std::string searchString)
static std::string toString(const wxString &source)

References ProximToolbox::disassemblyWindow(), find(), findNextBtn_, findPrevBtn_, infoLabel_, matchedLines, opInput_, ProximDisassemblyWindow::showAddress(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ reset()

void FindWindow::reset ( )
virtual

Called when the simulator program, memory and machine models are reset.

Reimplemented from ProximSimulatorWindow.

Definition at line 76 of file FindWindow.cc.

76 {
77 // Do nothing.
78}

Member Data Documentation

◆ findNextBtn_

wxButton* FindWindow::findNextBtn_
private

Definition at line 67 of file FindWindow.hh.

Referenced by createContents(), and onInputText().

◆ findPrevBtn_

wxButton* FindWindow::findPrevBtn_
private

Definition at line 66 of file FindWindow.hh.

Referenced by createContents(), and onInputText().

◆ infoLabel_

wxStaticText* FindWindow::infoLabel_
private

Definition at line 65 of file FindWindow.hh.

Referenced by createContents(), onFindNext(), onFindPrev(), and onInputText().

◆ matchCase_

wxCheckBox* FindWindow::matchCase_
private

Definition at line 64 of file FindWindow.hh.

Referenced by createContents(), and find().

◆ matchedIndex

int FindWindow::matchedIndex
private

Currently displayed codeline index in matchedLines.

Definition at line 72 of file FindWindow.hh.

Referenced by find(), onFindNext(), and onFindPrev().

◆ matchedLines

std::vector<int> FindWindow::matchedLines
private

List of code linenumbers where serached text was found.

Definition at line 70 of file FindWindow.hh.

Referenced by find(), onFindNext(), onFindPrev(), and onInputText().

◆ opInput_

wxTextCtrl* FindWindow::opInput_
private

Definition at line 63 of file FindWindow.hh.

Referenced by createContents(), and onInputText().


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