4 humberto 1.1.2.1 PEGASUS_NAMESPACE_BEGIN
5
6 CQLChainedIdentifierRep::CQLChainedIdentifierRep(String inString)
7 {
8 parse(inString);
9 }
10
11 CQLChainedIdentifierRep::CQLChainedIdentifierRep(CQLIdentifier &id)
12 {
13 _subIdentifiers.append(id);
14 }
15
16 CQLChainedIdentifierRep::CQLChainedIdentifierRep(const CQLChainedIdentifierRep& rep){
17 _subIdentifiers = rep.getSubIdentifiers();
18 }
19
20 const Array<CQLIdentifier>& CQLChainedIdentifierRep::getSubIdentifiers()const
21 {
22 return _subIdentifiers;
23 }
24
25 humberto 1.1.2.1 CQLIdentifier CQLChainedIdentifierRep::getLastIdentifier(){
26 if(_subIdentifiers.size() > 0)
27 return _subIdentifiers[_subIdentifiers.size()-1];
28 return CQLIdentifier();
29 }
30
31 String CQLChainedIdentifierRep::toString()const{
32 String s;
33 for(Uint32 i = 0; i < _subIdentifiers.size(); i++){
34 s.append(_subIdentifiers[i].toString());
35 if(i < _subIdentifiers.size() - 1)
36 s.append(".");
37 }
38 return s;
39 }
40
41 void CQLChainedIdentifierRep::append(CQLIdentifier & id){
42 _subIdentifiers.append(id);
43 }
44
45 Boolean CQLChainedIdentifierRep::isSubChain(CQLChainedIdentifier & chain){
46 humberto 1.1.2.1 Array<CQLIdentifier> ids = chain.getSubIdentifiers();
47 for(Uint32 i = 0; i < ids.size(); i++){
48 if(ids[i] != _subIdentifiers[i].getName())
49 return false;
50 }
51 return true;
52 }
53
54 CQLIdentifier& CQLChainedIdentifierRep::operator[](Uint32 index){
55 return _subIdentifiers[index];
56 }
57
58 Uint32 CQLChainedIdentifierRep::size(){
59 return _subIdentifiers.size();
60 }
61
62 Boolean CQLChainedIdentifierRep::prepend(CQLIdentifier & id){
63 /*
64 Compare id against the first element in _subIdentifiers,
65 if not an exact match, then prepend. This is used to fully
66 qualify the chained identifier.
67 humberto 1.1.2.1 */
68 if(id != _subIdentifiers[0]){
69 _subIdentifiers.prepend(id);
70 return true;
71 }
72 return false;
73 }
74
75 void CQLChainedIdentifierRep::applyScopes(Array<CQLScope>& scopes){
76
77 }
78
79 void CQLChainedIdentifierRep::parse(String & string){
80 /*
81 - parse string on "."
82 - start from the end of string
83 - if more than one substring found,
84 -- store first found string then
85 -- prepend remaining substrings
86 */
87 Char16 delim('.');
88 humberto 1.1.2.1 Uint32 index;
89 String range;
90
91 /* remove any array ranges so we dont parse a false . */
92 if((index = string.find("[")) != PEG_NOT_FOUND){
93 range = string.subString(index);
94 string.remove(index);
95 }
96
97 index = string.reverseFind(delim);
98 if(index == PEG_NOT_FOUND){
99 /* append the range we may have removed */
100 string.append(range);
101 _subIdentifiers.append(CQLIdentifier(string));
102 }else{
103 /* append the range we may have removed */
104 String tmp = string.subString(index+1);
105 tmp.append(range);
106 PEGASUS_STD(cout) << "tmp = " << tmp << PEGASUS_STD(endl);
107 _subIdentifiers.append(CQLIdentifier(tmp));
108
109 humberto 1.1.2.1 while(index != PEG_NOT_FOUND){
110 tmp = string.subString(0,index);
111 index = tmp.reverseFind(delim);
112 if(index == PEG_NOT_FOUND){
113 _subIdentifiers.prepend(CQLIdentifier(tmp));
114 }
115 else{
116 _subIdentifiers.prepend(CQLIdentifier(tmp.subString(index+1)));
117 }
118 }
119 }
120 }
121
122 PEGASUS_NAMESPACE_END
|