File: CQueryTreeBuilder.cc

package info (click to toggle)
gnuift 0.1.14%2Bds-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,632 kB
  • ctags: 2,973
  • sloc: cpp: 15,867; sh: 8,281; ansic: 1,812; perl: 1,007; php: 651; makefile: 483; lisp: 344
file content (129 lines) | stat: -rw-r--r-- 3,645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "libMRML/include/my_throw.h"
#include "libMRML/include/GIFTExceptions.h"
#include "libMRML/include/CQueryTreeBuilder.h"
#include "libMRML/include/CAlgorithm.h"
#include "libMRML/include/mrml_const.h"
#include <cstring>
//----------------------------------------

CQueryTreeBuilder::CQueryTreeBuilder(){};

/** 
    Building a query tree out of the information we have gathered
    true indicates success...
*/
pair<CQueryContainer*,CQueryTreeNode*> CQueryTreeBuilder::buildQueryTree(CAlgorithm& inAlgorithm,
									 CAccessorAdminCollection& inBaseConfiguration,
									 CStaticQueryFactory& inBaseTypeFactory,
									 CQueryContainer* inoutContainer)const{

//   cout << __FILE__ << ":" << __LINE__ << ":WARNING returning 0,0 as query tree" << endl;
//   cerr << __FILE__ << ":" << __LINE__ << ":WARNING returning 0,0 as query tree" << endl;
//   return pair<CQueryContainer*,CQueryTreeNode*>(0,0);

  //
  // 1. generate a CQuery structure with the right type
  //
  cout << "[mQ:"
       << inAlgorithm.getBaseType()
       << endl;  
  CQueryTreeNode* lRoot=new CQueryTreeNode();
  
  if(!inoutContainer){
    inoutContainer=new CQueryContainer();
  }
  

  //  CSelfDestroyPointer<list< pair<string,string> > > lAttributes=inAlgorithm.createNamedValueList();
  cout << "mQ]"<<endl;

  //
  // 2. generate an entry for the new CQuery structure in the mQueryContainer
  //
  (*inoutContainer)[inAlgorithm.getID()]=lRoot;
  

  // 
  // 3. Then build the query trees of the children and 
  // add each child both to the query finding structure
  // as to the query tree.
  //
  for(CXMLElement::lCChildren::const_iterator i=inAlgorithm.child_list_begin();
      i!=inAlgorithm.child_list_end();
      i++) if((*i)->getTypeOfNode()==CXMLElement::cElementNode){
    CXMLElement* lDereferencedI=*i;
    
    CAlgorithm*  iAlgorithm=(CAlgorithm*)(lDereferencedI);
    
    cout << "Build subalgorithm"
	 << lDereferencedI
	 << " {"
	 << iAlgorithm->getName()
	 << "}:"
	 << iAlgorithm->getBaseType()
	 << endl;
    
    // check, that this XML element is really an algorithm
    if(iAlgorithm->getName()==mrml_const::algorithm){
	cout << "really doing it" << endl;
	pair<CQueryContainer*,CQueryTreeNode*> lNewNode=buildQueryTree(*iAlgorithm,
								       inBaseConfiguration,
								       inBaseTypeFactory,
								       inoutContainer);
	
	lRoot->addChild(lNewNode.second,
			iAlgorithm->getWeight());
    }
  }
  //
  // at the end, we tell the query structure
  // that it has recieved all the data it can
  // get, and that it better should get ready.
  //
  cout << "hier " 
       << flush
       << endl;
  
  cout << inAlgorithm.getID()
       << flush
       << endl;
  

  //
  // In the very end configure the root
  //
  lRoot->configure(inAlgorithm,
		   inBaseConfiguration,
		   inBaseTypeFactory);

  return make_pair(inoutContainer,lRoot);
}

//----------------------------------------
/** given an ID find the right item in the 
    query tree */
CQueryTreeNode* CQueryContainer::getQueryByID(const string& inID)const{
  
  const_iterator lFound=find(inID);
  if(lFound==end()){
    cout << "THROWING UP IN getQueryByID" 
	 << endl;

    string lThrowString=
      string("Current content of mQueryContainer \n");
    for(const_iterator i=begin();
	i!=end();
	i++){
      lThrowString+=i->first + string(",\n");
    }
    lThrowString+=string("\n and we were searching for ")+inID;
//     if(size()){
//       cerr << lThrowString << flush << endl; 
//       return begin()->second;
//     }    
    my_throw(VENotFound(strdup(lThrowString.c_str())));
    return 0;
  }else{
    return lFound->second;
  }
}