[Avida-SVN] r1181 - in development: . source/analyze
avidaedward at myxo.css.msu.edu
avidaedward at myxo.css.msu.edu
Thu Jan 11 14:12:26 PST 2007
Author: avidaedward
Date: 2007-01-11 17:12:26 -0500 (Thu, 11 Jan 2007)
New Revision: 1181
Modified:
development/
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyze.h
development/source/analyze/cAnalyzeGenotype.h
Log:
r1174 at stochastic: kaben | 2006-12-19 20:47:56 -0500
- Added "bool cAnalyze::Send(const cString &)".
- This can be used to send high-level "analyze" commands to cAnalyze
instances from within c++ code. In particular, it helps with
low-level tests of cAnalyze code after sequences of high-level
operations. I'm using it to test algorithms and ideas for lineage
tree operations.
- cAnalyze has lots of duplication of the sort of code found in
Send(). Looks like a good target for refactoring.
- Finished construction and tests of cAnalyzeGenotypeLink and its
interactions with cAnalyzeGenotype. All seems well. Now in a good
place to continue work with Gabes various tree analyses, first of
which is "cumulative stemminess".
Property changes on: development
___________________________________________________________________
Name: svk:merge
- 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/development:1161
+ 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/development:1174
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2007-01-11 21:55:22 UTC (rev 1180)
+++ development/source/analyze/cAnalyze.cc 2007-01-11 22:12:26 UTC (rev 1181)
@@ -7967,3 +7967,42 @@
if (!saved_analyze) m_ctx.ClearAnalyzeMode();
}
+
+bool cAnalyze::Send(const cString &text_input)
+{
+ cString cur_input(text_input);
+ cString command = cur_input.PopWord();
+
+ cAnalyzeCommand* cur_command;
+ cAnalyzeCommandDefBase* command_def = FindAnalyzeCommandDef(command);
+ if (command == "") {
+ // Don't worry about blank lines...
+ ;
+ } else if (command_def != NULL && command_def->IsFlowCommand() == true) {
+ // This code has a body to it... fill it out!
+ cur_command = new cAnalyzeFlowCommand(command, cur_input);
+ InteractiveLoadCommandList(*(cur_command->GetCommandList()));
+ } else {
+ // This is a normal command...
+ cur_command = new cAnalyzeCommand(command, cur_input);
+ }
+
+ cString args = cur_command->GetArgs();
+ PreProcessArgs(args);
+
+ cAnalyzeCommandDefBase* command_fun = FindAnalyzeCommandDef(command);
+
+ // First check for built-in functions...
+ if (command_fun != NULL) command_fun->Run(this, args, *cur_command);
+
+ // Then for user defined functions
+ else if (FunctionRun(command, args) == true) { }
+
+ // Otherwise, give an error.
+ else {
+ cerr << "Error: Unknown command '" << command << "'." << endl;
+ return false;
+ }
+
+ return true;
+}
Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h 2007-01-11 21:55:22 UTC (rev 1180)
+++ development/source/analyze/cAnalyze.h 2007-01-11 22:12:26 UTC (rev 1181)
@@ -276,6 +276,7 @@
void RunFile(cString filename);
void RunInteractive();
+ bool Send(const cString &text_input);
int GetCurrentBatchID() { return cur_batch; }
cGenotypeBatch& GetCurrentBatch() { return batch[cur_batch]; }
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2007-01-11 21:55:22 UTC (rev 1180)
+++ development/source/analyze/cAnalyzeGenotype.h 2007-01-11 22:12:26 UTC (rev 1181)
@@ -42,20 +42,26 @@
class cTestCPU;
class cWorld;
-/* FIXME : Refactor. @kgn */
+
class cAnalyzeGenotype;
class cAnalyzeGenotypeLink {
private:
cAnalyzeGenotype *m_parent;
tList<cAnalyzeGenotype> m_child_list;
public:
- cAnalyzeGenotypeLink():m_parent(0) {
+ cAnalyzeGenotypeLink(){
SetParent(0);
- ClearChildren();
+ m_child_list.Clear();
}
- void SetParent(cAnalyzeGenotype *parent){ m_parent = parent; }
- cAnalyzeGenotype *GetParent(){ return m_parent; }
- tList<cAnalyzeGenotype> &GetChildList(){ return m_child_list; }
+ void SetParent(cAnalyzeGenotype *parent){
+ m_parent = parent;
+ }
+ cAnalyzeGenotype *GetParent(){
+ return m_parent;
+ }
+ tList<cAnalyzeGenotype> &GetChildList(){
+ return m_child_list;
+ }
cAnalyzeGenotype *FindChild(cAnalyzeGenotype *child){
return GetChildList().FindPtr(child);
}
@@ -67,9 +73,6 @@
GetChildList().PushRear(child);
}
}
- void ClearChildren(){
- m_child_list.Clear();
- }
};
@@ -349,27 +352,43 @@
*/
bool operator==(const cAnalyzeGenotype &in) const { return &in == this; }
- cAnalyzeGenotypeLink &GetLink(){ return m_link; }
+ cAnalyzeGenotypeLink &GetLink(){
+ return m_link;
+ }
+ cAnalyzeGenotype *GetParent(){
+ return GetLink().GetParent();
+ }
void LinkParent(cAnalyzeGenotype *parent){
- if(GetLink().GetParent() && GetLink().GetParent() != parent){
- GetLink().GetParent()->GetLink().RemoveChild(this);
+ if(GetParent() && GetParent() != parent){
+ GetParent()->GetLink().RemoveChild(this);
}
GetLink().SetParent(parent);
- if(parent){ parent->GetLink().AddChild(this); }
+ if(parent){
+ parent->GetLink().AddChild(this);
+ }
}
- void LinkChild(cAnalyzeGenotype &child){ child.LinkParent(this); }
- void UnlinkParent(){ LinkParent(0); }
+ void LinkChild(cAnalyzeGenotype &child){
+ child.LinkParent(this);
+ }
+ void UnlinkParent(){
+ LinkParent(0);
+ }
+ tList<cAnalyzeGenotype> &GetChildList(){
+ return GetLink().GetChildList();
+ }
void UnlinkChildren(){
- tListIterator<cAnalyzeGenotype> it(GetLink().GetChildList());
- while (it.Next() != NULL) { it.Get()->GetLink().SetParent(0); }
- GetLink().ClearChildren();
+ tListIterator<cAnalyzeGenotype> it(GetChildList());
+ while (it.Next() != NULL) {
+ it.Get()->UnlinkParent();
+ }
}
void Unlink(){
UnlinkParent();
UnlinkChildren();
}
- cAnalyzeGenotype *GetParent(){ return GetLink().GetParent(); }
- bool HasChild(cAnalyzeGenotype &child){ return GetLink().FindChild(&child); }
+ bool HasChild(cAnalyzeGenotype &child){
+ return GetLink().FindChild(&child);
+ }
bool UnlinkChild(cAnalyzeGenotype &child){
if(HasChild(child)){
child.UnlinkParent();
@@ -378,7 +397,6 @@
return false;
}
}
- tList<cAnalyzeGenotype> &GetChildList(){ return GetLink().GetChildList(); }
};
#endif
More information about the Avida-cvs
mailing list