Logo ROOT   6.16/01
Reference Guide
TSchemaRule.cxx
Go to the documentation of this file.
1// @(#)root/core:$Id$
2// author: Lukasz Janyst <ljanyst@cern.ch>
3
4#include "TSchemaRule.h"
5
7#include "TClassEdit.h"
9#include "TSchemaType.h"
10#include "TObjArray.h"
11#include "TObjString.h"
12#include "TNamed.h"
13#include <utility>
14#include <iostream>
15#include <vector>
16#include <list>
17#include <string>
18#include <cstdlib>
19#include "TROOT.h"
20#include "Riostream.h"
21
23
24using namespace ROOT;
25
26namespace {
27 static Bool_t IsIrrelevantCharacter(char c)
28 {
29 return (c == ' ' || c == '\n' || c == '\t');
30 }
31
32 static void AdvanceOverIrrelevantCharacter(const char*& str)
33 {
34 while (IsIrrelevantCharacter(*str)) {
35 ++str;
36 }
37 }
38
39 // check if lhs matches rhs if we ignore irelevant white space differences
40
41 static Bool_t IsCodeEquivalent(const TString& lhs, const TString& rhs)
42 {
43 Bool_t result = kTRUE;
44
45 if (lhs != rhs) {
46 const char null = '\0';
47 const char* left = lhs.Data();
48 const char* right = rhs.Data();
49 Bool_t literal = false;
50 // skip initial white space
51 AdvanceOverIrrelevantCharacter(left);
52 AdvanceOverIrrelevantCharacter(right);
53
54 while (*left != null || *right != null) {
55 // If both chars are white space, skip consecutive white space
56 if (!literal && IsIrrelevantCharacter(*left) && IsIrrelevantCharacter(*right)) {
57 AdvanceOverIrrelevantCharacter(left);
58 AdvanceOverIrrelevantCharacter(right);
59 continue;
60 }
61 // Check if one string has trailing white space, and the other doesn't.
62 if (*left == null || *right == null) {
63 AdvanceOverIrrelevantCharacter(left);
64 AdvanceOverIrrelevantCharacter(right);
65 result = (*left == null && *right == null);
66 break;
67 }
68
69 if (*left != *right) {
70 result = kFALSE;
71 break;
72 }
73
74 if (*left == '"') {
75 literal = !literal;
76 }
77 ++left;
78 ++right;
79 }
80 }
81 return result;
82 }
83
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Default Constructor.
88
89TSchemaRule::TSchemaRule(): fVersionVect( 0 ), fChecksumVect( 0 ),
90 fTargetVect( 0 ), fSourceVect( 0 ),
91 fIncludeVect( 0 ), fEmbed( kTRUE ),
92 fReadFuncPtr( 0 ), fReadRawFuncPtr( 0 ),
93 fRuleType( kNone )
94{
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Destructor.
99
101{
102 delete fVersionVect;
103 delete fChecksumVect;
104 delete fTargetVect;
105 delete fSourceVect;
106 delete fIncludeVect;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Copy Constructor.
111
113 fVersionVect( 0 ), fChecksumVect( 0 ),
114 fTargetVect( 0 ), fSourceVect( 0 ),
115 fIncludeVect( 0 ), fEmbed( kTRUE ),
116 fReadFuncPtr( 0 ), fReadRawFuncPtr( 0 ),
117 fRuleType( kNone )
118{
119 *this = rhs;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Copy operator.
124
126{
127 if( this != &rhs ) {
128 fVersion = rhs.fVersion;
129 fChecksum = rhs.fChecksum;
131 fTarget = rhs.fTarget;
132 fSource = rhs.fSource;
133 fInclude = rhs.fInclude;
134 fCode = rhs.fCode;
135 fEmbed = rhs.fEmbed;
138 fRuleType = rhs.fRuleType;
140 }
141 return *this;
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Return true if the rule have the same effects.
146
148{
149 if( this != &rhs ) {
150 Bool_t result = ( fVersion == rhs.fVersion
151 && fChecksum == rhs.fChecksum
152 && fSourceClass == rhs.fSourceClass
153 && fTargetClass == rhs.fTargetClass
154 && fSource == rhs.fSource
155 && fTarget == rhs.fTarget
156 && fInclude == rhs.fInclude
157 && IsCodeEquivalent(fCode, rhs.fCode)
158 && fEmbed == rhs.fEmbed
159 && fRuleType == rhs.fRuleType
160 && fAttributes == rhs.fAttributes );
161 if (result &&
163 || (fReadFuncPtr != rhs.fReadFuncPtr && fReadFuncPtr != 0 && rhs.fReadFuncPtr != 0) ) )
164 {
165 result = kFALSE;
166 }
167
168 return result;
169 }
170 return kTRUE;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// The ls function lists the contents of a class on stdout. Ls output
175/// is typically much less verbose then Dump().
176
177void TSchemaRule::ls(Option_t *targetname) const
178{
180 std::cout << "Schema Evolution Rule: ";
181 if (fRuleType==kReadRule) std::cout << "read ";
182 else if (fRuleType==kReadRawRule) std::cout << "readraw ";
183 std::cout << "\n";
186 std::cout << "sourceClass=\"" << fSourceClass << "\" ";
187 if (fVersion.Length()) std::cout << "version=\"" << fVersion << "\" ";
188 if (fChecksum.Length()) std::cout << "checksum=\"" << fChecksum << "\" ";
189 if (targetname && targetname[0]) std::cout << "targetClass=\"" << targetname << "\" ";
190 else std::cout << "targetClass\"" << fTargetClass << "\" ";
191 std::cout << "\n";
193 std::cout << "source=\"" << fSource << "\" ";
194 std::cout << "target=\"" << fTarget << "\" ";
195 std::cout << "\n";
196 if (fInclude.Length()) {
198 std::cout << "include=\"" << fInclude << "\" " << "\n";
199 }
200 if (fAttributes.Length()) {
202 std::cout << "attributes=\"" << fAttributes << "\"" << "\n";
203 }
204 if (fCode.Length()) {
206 std::cout << "code=\"{" << fCode << "}\" "
207 << "\n";
208 }
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Add to the string 'out' the string representation of the rule.
214/// if options contains:
215/// 's' : add the short form of the rule is possible
216/// 'x' : add the xml form of the rule
217
218void TSchemaRule::AsString(TString &out, const char *options) const
219{
220 TString opt(options);
221 opt.ToLower();
222 Bool_t shortform = opt.Contains('s');
223 Bool_t xmlform = opt.Contains('x');
224
225 TString end;
226 if (xmlform) {
227 /*
228 <read sourceClass="ClassA" version="[2]" targetClass="ClassA" source="int m_unit;" target="m_unit" >
229 <![CDATA[ { m_unit = 10*onfile.m_unit; } ]]>
230 </read>
231 */
232 shortform = kFALSE;
233 out += "<";
234 if (fRuleType==kReadRule) { out += "read "; end = "</read>"; }
235 else if (fRuleType==kReadRawRule) { out += "readraw "; end = "</readraw>"; }
236 else { out += "-- "; end = "-->"; }
237
238 } else {
239 if (!shortform || fRuleType!=kReadRule) {
240 out += "type=";
241 if (fRuleType==kReadRule) out += "read ";
242 else if (fRuleType==kReadRawRule) out += "readraw ";
243 else out += " ";
244 }
245 }
246 if (!shortform || (fSourceClass != fTargetClass) ) {
247 out += "sourceClass=\"" + fSourceClass + "\" ";
248 out += "targetClass=\"" + fTargetClass + "\" ";
249 } else {
250 out += fSourceClass + " ";
251 }
252 if (shortform && fTarget == fSource) {
253 out += fSource + " ";
254 }
255 if (!shortform || (fVersion != "[1-]")) {
256 if (fVersion.Length()) out += "version=\"" + fVersion + "\" ";
257 }
258 if (fChecksum.Length()) out += "checksum=\"" + fChecksum + "\" ";
259 if (!shortform || fTarget != fSource) {
260 out += "source=\"" + fSource + "\" ";
261 out += "target=\"" + fTarget + "\" ";
262 }
263 if (fInclude.Length()) out += "include=\"" + fInclude + "\" ";
264 if (fAttributes.Length()) out += "attributes=\"" + fAttributes + "\" ";
265 if (xmlform) {
266 out += "> ";
267 }
268 if (xmlform) {
269 if (fCode.Length()) {
270 out += "\n<![CDATA[ { " + fCode + " ]]>\n ";
271 } else if (fReadFuncPtr) {
272 // Can we guess?
273 // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
274 } else if (fReadRawFuncPtr) {
275 // Can we guess?
276 // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";
277 }
278 } else {
279 if (fCode.Length()) {
280 out += "code=\"{" + fCode + "}\" ";
281 } else if (fReadFuncPtr) {
282 // Can we guess?
283 // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
284 } else if (fReadRawFuncPtr) {
285 // Can we guess?
286 // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";
287 }
288 }
289 if (xmlform) {
290 out += end;
291 }
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Zero out this rule object.
296
297void TSchemaRule::Clear( const char * /* option */)
298{
299 fVersion.Clear();
300 fChecksum.Clear();
301 fSourceClass.Clear();
302 fTarget.Clear();
303 fSource.Clear();
304 fInclude.Clear();
305 fCode.Clear();
306 fAttributes.Clear();
307 fReadRawFuncPtr = 0;
308 fReadFuncPtr = 0;
310 delete fVersionVect; fVersionVect = 0;
311 delete fChecksumVect; fChecksumVect = 0;
312 delete fTargetVect; fTargetVect = 0;
313 delete fSourceVect; fSourceVect = 0;
314 delete fIncludeVect; fIncludeVect = 0;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Set the content fot this object from the rule
319/// See TClass::AddRule for details on the syntax.
320
322{
323 //-----------------------------------------------------------------------
324 // Parse the rule and check it's validity
325 /////////////////////////////////////////////////////////////////////////////
326
328
329 std::string error_string;
330 if( !ROOT::ParseRule(rule, rule_values, error_string) ) {
331 Error("SetFromRule","The rule (%s) is invalid: %s",rule,error_string.c_str());
332 return kFALSE;
333 }
334 ROOT::Internal::MembersMap_t::const_iterator it1;
335
336 it1 = rule_values.find( "type" );
337 if( it1 != rule_values.end() ) {
338 if (it1->second == "read" || it1->second == "Read") {
340 } else if (it1->second == "readraw" || it1->second == "ReadRaw") {
342 } else {
344 }
345 } else {
346 // Default to read.
348 }
349 it1 = rule_values.find( "targetClass" );
350 if( it1 != rule_values.end() ) SetTargetClass( it1->second );
351 it1 = rule_values.find( "sourceClass" );
352 if( it1 != rule_values.end() ) SetSourceClass( it1->second );
353 it1 = rule_values.find( "target" );
354 if( it1 != rule_values.end() ) SetTarget( it1->second );
355 it1 = rule_values.find( "source" );
356 if( it1 != rule_values.end() ) SetSource( it1->second );
357 it1 = rule_values.find( "version" );
358 if( it1 != rule_values.end() ) SetVersion( it1->second );
359 it1 = rule_values.find( "checksum" );
360 if( it1 != rule_values.end() ) SetChecksum( it1->second );
361 it1 = rule_values.find( "embed" );
362 if( it1 != rule_values.end() ) SetEmbed( it1->second == "false" ? false : true );
363 it1 = rule_values.find( "include" );
364 if( it1 != rule_values.end() ) SetInclude( it1->second );
365 it1 = rule_values.find( "attributes" );
366 if( it1 != rule_values.end() ) SetAttributes( it1->second );
367 it1 = rule_values.find( "code" );
368 if( it1 != rule_values.end() ) SetCode( it1->second );
369 // if (code is functioname) {
370 // switch (ruleobj->GetRuleType() ) {
371 // case kRead: SetReadFunctionPointer( )
372 // case kReadRewa: SetReadRawFunctionPointer( )
373 // }
374
375 return kTRUE;
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Set the version string - returns kFALSE if the format is incorrect
380
381Bool_t TSchemaRule::SetVersion( const TString& version )
382{
383 fVersion = "";
384 Bool_t ret = ProcessVersion( version );
385 if( ret )
386 fVersion = version;
387 return ret;
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Get the version string.
392
393const char *TSchemaRule::GetVersion() const
394{
395 return fVersion;
396}
397
398
399////////////////////////////////////////////////////////////////////////////////
400/// Check if given version number is defined in this rule
401
403{
404 if( fVersion == "" )
405 return kFALSE;
406
407 if( !fVersionVect )
408 ProcessVersion( fVersion ); // At this point the version string should always be correct
409
410 if (version == -1) {
411 version = 1;
412 }
413
414 std::vector<std::pair<Int_t, Int_t> >::iterator it;
415 for( it = fVersionVect->begin(); it != fVersionVect->end(); ++it ) {
416 if( version >= it->first && version <= it->second )
417 return kTRUE;
418 }
419 return kFALSE;
420}
421
422////////////////////////////////////////////////////////////////////////////////
423/// Set the checksum string - returns kFALSE if the format is incorrect
424
425Bool_t TSchemaRule::SetChecksum( const TString& checksum )
426{
427 fChecksum = "";
428 Bool_t ret = ProcessChecksum( checksum );
429 if( ret )
430 fChecksum = checksum;
431 return ret;
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Check if given checksum is defined in this rule
436
438{
439 if( fChecksum == "" )
440 return kFALSE;
441
442 if( !fChecksumVect )
443 ProcessChecksum( fChecksum ); // At this point the checksum string should always be correct
444
445 std::vector<UInt_t>::iterator it;
446 for( it = fChecksumVect->begin(); it != fChecksumVect->end(); ++it ) {
447 if( checksum == *it )
448 return kTRUE;
449 }
450 return kFALSE;
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Set the source class of this rule (i.e. the onfile class).
455
456void TSchemaRule::SetSourceClass( const TString& classname )
457{
458 std::string normalizedName;
459 TClassEdit::GetNormalizedName(normalizedName, classname);
460 fSourceClass = normalizedName;
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// Get the source class of this rule (i.e. the onfile class).
465
467{
468 return fSourceClass;
469}
470
471////////////////////////////////////////////////////////////////////////////////
472/// Set the target class of this rule (i.e. the in memory class).
473
474void TSchemaRule::SetTargetClass( const TString& classname )
475{
476 std::string normalizedName;
477 TClassEdit::GetNormalizedName(normalizedName, classname);
478 fTargetClass = normalizedName;
479}
480
481////////////////////////////////////////////////////////////////////////////////
482/// Get the targte class of this rule (i.e. the in memory class).
483
485{
486 return fTargetClass;
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Set the target member of this rule (i.e. the in memory data member).
491
492void TSchemaRule::SetTarget( const TString& target )
493{
494 fTarget = target;
495
496 if( target == "" ) {
497 delete fTargetVect;
498 fTargetVect = 0;
499 return;
500 }
501
502 if( !fTargetVect ) {
503 fTargetVect = new TObjArray();
505 }
506 ProcessList( fTargetVect, target );
507}
508
509////////////////////////////////////////////////////////////////////////////////
510/// Get the target data members of this rule as a simple string (i.e. the in memory data member).
511
513{
514 return fTarget;
515}
516
517////////////////////////////////////////////////////////////////////////////////
518/// Get the target data members of this rule (i.e. the in memory data member).
519
521{
522 if( fTarget == "" )
523 return 0;
524
525 if( !fTargetVect ) {
526 fTargetVect = new TObjArray();
529 }
530
531 return fTargetVect;
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Set the list of source members. This should be in the form of a declaration:
536/// Int_t fOldMember; TNamed fName;
537
538void TSchemaRule::SetSource( const TString& source )
539{
540 fSource = source;
541
542 if( source == "" ) {
543 delete fSourceVect;
544 fSourceVect = 0;
545 return;
546 }
547
548 if( !fSourceVect ) {
549 fSourceVect = new TObjArray();
551 }
552
554}
555
556////////////////////////////////////////////////////////////////////////////////
557/// Get the list of source members as a TObjArray of TNamed object,
558/// with the name being the member name and the title being its type.
559
561{
562 if( fSource == "" )
563 return 0;
564
565 if( !fSourceVect ) {
566 fSourceVect = new TObjArray();
569 }
570 return fSourceVect;
571}
572
573////////////////////////////////////////////////////////////////////////////////
574/// Set the comma separated list of header files to include to be able
575/// to compile this rule.
576
577void TSchemaRule::SetInclude( const TString& incl )
578{
579 fInclude = incl;
580
581 if( incl == "" ) {
582 delete fIncludeVect;
583 fIncludeVect = 0;
584 return;
585 }
586
587 if( !fIncludeVect ) {
588 fIncludeVect = new TObjArray();
590 }
591
592 ProcessList( fIncludeVect, incl );
593}
594
595////////////////////////////////////////////////////////////////////////////////
596/// Return the list of header files to include to be able to
597/// compile this rule as a TObjArray of TObjString
598
600{
601 if( fInclude == "" )
602 return 0;
603
604 if( !fIncludeVect ) {
605 fIncludeVect = new TObjArray();
608 }
609
610 return fIncludeVect;
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// Set whether this rule should be save in the ROOT file (if true)
615
617{
618 fEmbed = embed;
619}
620
621////////////////////////////////////////////////////////////////////////////////
622/// Return true if this rule should be saved in the ROOT File.
623
625{
626 return fEmbed;
627}
628
629////////////////////////////////////////////////////////////////////////////////
630/// Return kTRUE if this rule is valid.
631
633{
634 return (fVersionVect || fChecksumVect) && (fSourceClass.Length() != 0);
635}
636
637////////////////////////////////////////////////////////////////////////////////
638/// Set the source code of this rule.
639
640void TSchemaRule::SetCode( const TString& code )
641{
642 fCode = code;
643}
644
645////////////////////////////////////////////////////////////////////////////////
646/// Get the source code of this rule.
647
648const char *TSchemaRule::GetCode() const
649{
650 return fCode;
651}
652
653////////////////////////////////////////////////////////////////////////////////
654/// Set the attributes code of this rule.
655
656void TSchemaRule::SetAttributes( const TString& attributes )
657{
658 fAttributes = attributes;
659}
660
661////////////////////////////////////////////////////////////////////////////////
662/// Get the attributes code of this rule.
663
664const char *TSchemaRule::GetAttributes() const
665{
666 return fAttributes;
667}
668
669////////////////////////////////////////////////////////////////////////////////
670/// Return true if one of the rule's data member target is 'target'.
671
672Bool_t TSchemaRule::HasTarget( const TString& target ) const
673{
674 if( !fTargetVect )
675 return kFALSE;
676
677 TObject* obj;
679 while( (obj = it.Next()) ) {
680 TObjString* str = (TObjString*)obj;
681 if( str->GetString() == target )
682 return kTRUE;
683 }
684 return kFALSE;
685}
686
687////////////////////////////////////////////////////////////////////////////////
688/// Return true if one of the rule's data member source is 'source'
689
690Bool_t TSchemaRule::HasSource( const TString& source ) const
691{
692 if( !fSourceVect )
693 return kFALSE;
694
695 TObject* obj;
697 while( (obj = it.Next()) ) {
698 TSources* var = (TSources*)obj;
699 if( var->GetName() == source )
700 return kTRUE;
701 }
702 return kFALSE;
703}
704
705////////////////////////////////////////////////////////////////////////////////
706/// Set the pointer to the function to be run for the rule (if it is a read rule).
707
709{
710 fReadFuncPtr = ptr;
711}
712
713////////////////////////////////////////////////////////////////////////////////
714/// Get the pointer to the function to be run for the rule (if it is a read rule).
715
717{
718 return fReadFuncPtr;
719}
720
721////////////////////////////////////////////////////////////////////////////////
722/// Set the pointer to the function to be run for the rule (if it is a raw read rule).
723
725{
726 fReadRawFuncPtr = ptr;
727}
728
729////////////////////////////////////////////////////////////////////////////////
730/// Get the pointer to the function to be run for the rule (if it is a raw read rule).
731
733{
734 return fReadRawFuncPtr;
735}
736
737////////////////////////////////////////////////////////////////////////////////
738/// Set the type of the rule.
739
741{
742 fRuleType = type;
743}
744
745////////////////////////////////////////////////////////////////////////////////
746/// Return kTRUE if the rule is a strict renaming of one of the data member of the class.
747
749{
750 return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget == "" && fSource == "" && fInclude == "" && fCode == "" && fAttributes == "";
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Return kTRUE if the rule is a strict renaming of the class to a new name.
755
757{
758 return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget != "" && fSource != "" && fInclude == "" && fCode == "" && fAttributes == "";
759}
760
761////////////////////////////////////////////////////////////////////////////////
762/// Return the type of the rule.
763
765{
766 return fRuleType;
767}
768
769////////////////////////////////////////////////////////////////////////////////
770/// Check if this rule conflicts with the given one.
771
773{
774 //---------------------------------------------------------------------------
775 // If the rules have different sources then the don't conflict
776 /////////////////////////////////////////////////////////////////////////////
777
778 if( fSourceClass != rule->fSourceClass )
779 return kFALSE;
780
781 //---------------------------------------------------------------------------
782 // Check if the rules have common target
783 /////////////////////////////////////////////////////////////////////////////
784
785 if( !rule->GetTarget() )
786 return kFALSE;
787
788 Bool_t haveCommonTargets = kFALSE;
789 TObjArrayIter titer( rule->GetTarget() );
790 TObjString *str;
791 TObject *obj;
792
793 while( (obj = titer.Next() ) ) {
794 str = (TObjString*)obj;
795 if( HasTarget( str->String() ) )
796 haveCommonTargets = kTRUE;
797 }
798
799 if( !haveCommonTargets )
800 return kFALSE;
801
802 //---------------------------------------------------------------------------
803 // Check if there are conflicting checksums
804 /////////////////////////////////////////////////////////////////////////////
805
806 if( fChecksumVect ) {
807 std::vector<UInt_t>::iterator it;
808 for( it = fChecksumVect->begin(); it != fChecksumVect->end(); ++it )
809 if( rule->TestChecksum( *it ) )
810 return kTRUE;
811 }
812
813 //---------------------------------------------------------------------------
814 // Check if there are conflicting versions
815 /////////////////////////////////////////////////////////////////////////////
816
817 if( fVersionVect && rule->fVersionVect )
818 {
819 std::vector<std::pair<Int_t, Int_t> >::iterator it1;
820 std::vector<std::pair<Int_t, Int_t> >::iterator it2;
821 for( it1 = fVersionVect->begin(); it1 != fVersionVect->end(); ++it1 ) {
822 for( it2 = rule->fVersionVect->begin();
823 it2 != rule->fVersionVect->end(); ++it2 ) {
824 //------------------------------------------------------------------
825 // the rules conflict it their version ranges intersect
826 ////////////////////////////////////////////////////////////////////
827
828 if( it1->first >= it2->first && it1->first <= it2->second )
829 return kTRUE;
830
831 if( it1->first < it2->first && it1->second >= it2->first )
832 return kTRUE;
833 }
834 }
835 }
836 return kFALSE;
837}
838
839////////////////////////////////////////////////////////////////////////////////
840/// Check if specified version string is correct and build version vector.
841
842Bool_t TSchemaRule::ProcessVersion( const TString& version ) const
843{
844 //---------------------------------------------------------------------------
845 // Check if we have valid list
846 /////////////////////////////////////////////////////////////////////////////
847
848 if( version[0] != '[' || version[version.Length()-1] != ']' )
849 return kFALSE;
850 std::string ver = version.Data();
851
852 std::list<std::string> versions;
853 Internal::TSchemaRuleProcessor::SplitList( ver.substr( 1, ver.size()-2), versions );
854
855 if( versions.empty() )
856 {
857 delete fVersionVect;
858 fVersionVect = 0;
859 return kFALSE;
860 }
861
862 if( !fVersionVect )
863 fVersionVect = new std::vector<std::pair<Int_t, Int_t> >;
864 fVersionVect->clear();
865
866 //---------------------------------------------------------------------------
867 // Check the validity of each list element
868 /////////////////////////////////////////////////////////////////////////////
869
870 std::list<std::string>::iterator it;
871 for( it = versions.begin(); it != versions.end(); ++it ) {
872 std::pair<Int_t, Int_t> verpair;
874 {
875 delete fVersionVect;
876 fVersionVect = 0;
877 return kFALSE;
878 }
879 fVersionVect->push_back( verpair );
880 }
881 return kTRUE;
882}
883
884////////////////////////////////////////////////////////////////////////////////
885/// Check if specified checksum string is correct and build checksum vector.
886
887Bool_t TSchemaRule::ProcessChecksum( const TString& checksum ) const
888{
889 //---------------------------------------------------------------------------
890 // Check if we have valid list
891 /////////////////////////////////////////////////////////////////////////////
892
893 if (!checksum[0])
894 return kFALSE;
895 std::string chk = (const char*)checksum;
896 if( chk[0] != '[' || chk[chk.size()-1] != ']' )
897 return kFALSE;
898
899 std::list<std::string> checksums;
900 Internal::TSchemaRuleProcessor::SplitList( chk.substr( 1, chk.size()-2), checksums );
901
902 if( checksums.empty() ) {
903 delete fChecksumVect;
904 fChecksumVect = 0;
905 return kFALSE;
906 }
907
908 if( !fChecksumVect )
909 fChecksumVect = new std::vector<UInt_t>;
910 fChecksumVect->clear();
911
912 //---------------------------------------------------------------------------
913 // Check the validity of each list element
914 /////////////////////////////////////////////////////////////////////////////
915
916 std::list<std::string>::iterator it;
917 for( it = checksums.begin(); it != checksums.end(); ++it ) {
919 delete fChecksumVect;
920 fChecksumVect = 0;
921 return kFALSE;
922 }
923 fChecksumVect->push_back( atoi( it->c_str() ) );
924 }
925 return kTRUE;
926}
927
928////////////////////////////////////////////////////////////////////////////////
929/// Split the list as a comma separated list into a TObjArray of TObjString.
930
931void TSchemaRule::ProcessList( TObjArray* array, const TString& list )
932{
933 std::list<std::string> elems;
934 std::list<std::string>::iterator it;
935 Internal::TSchemaRuleProcessor::SplitList( (const char*)list, elems );
936
937 array->Clear();
938
939 if( elems.empty() )
940 return;
941
942 for( it = elems.begin(); it != elems.end(); ++it ) {
943 TObjString *str = new TObjString;
944 *str = it->c_str();
945 array->Add( str );
946 }
947}
948
949////////////////////////////////////////////////////////////////////////////////
950/// Split the list as a declaration into as a TObjArray of TNamed(name,type).
951
952void TSchemaRule::ProcessDeclaration( TObjArray* array, const TString& list )
953{
954 std::list<std::pair<ROOT::Internal::TSchemaType,std::string> > elems;
955 std::list<std::pair<ROOT::Internal::TSchemaType,std::string> >::iterator it;
956 Internal::TSchemaRuleProcessor::SplitDeclaration( (const char*)list, elems );
957
958 array->Clear();
959
960 if( elems.empty() )
961 return;
962
963 for( it = elems.begin(); it != elems.end(); ++it ) {
964 TSources *type = new TSources( it->second.c_str(), it->first.fType.c_str(), it->first.fDimensions.c_str() ) ;
965 array->Add( type );
966 }
967}
968
969#if 0
970////////////////////////////////////////////////////////////////////////////////
971/// Generate the actual function for the rule.
972
973Bool_t TSchemaRule::GenerateFor( TStreamerInfo *info )
974{
975 String funcname = fSourceClass + "_to_" + fTargetClass;
976 if (info) funcname += "_v" + info->GetClassVersion();
977 TString names = fSource + "_" + fTarget;
978 name.ReplaceAll(',','_');
979 name.ReplaceAll(':','_');
980 funcname += "_" + name;
981
982 String filename = funcname + ".C";
983 if (!false) {
984 filename += '+';
985 }
986
987 std::ofstream fileout(filename);
988
989
990 ROOT::WriteReadRawRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
991 ROOT::WriteReadRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
992
993 gROOT->LoadMacro(filename);
994}
995
996#endif
const Handle_t kNone
Definition: GuiTypes.h:87
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
int type
Definition: TGX11.cxx:120
#define gROOT
Definition: TROOT.h:410
static bool IsANumber(const std::string &source)
static void SplitDeclaration(const std::string &source, std::list< std::pair< ROOT::Internal::TSchemaType, std::string > > &result)
static bool ProcessVersion(const std::string &source, std::pair< Int_t, Int_t > &result)
static void SplitList(const std::string &source, std::list< std::string > &result, char delimiter=',')
void SetRuleType(RuleType_t type)
Set the type of the rule.
TObjArray * fSourceVect
Definition: TSchemaRule.h:113
void SetCode(const TString &code)
Set the source code of this rule.
TString fCode
Includes vector.
Definition: TSchemaRule.h:116
void SetTarget(const TString &target)
Set the target member of this rule (i.e. the in memory data member).
ReadFuncPtr_t fReadFuncPtr
Definition: TSchemaRule.h:118
TObjArray * fIncludeVect
Definition: TSchemaRule.h:115
void SetReadRawFunctionPointer(ReadRawFuncPtr_t ptr)
Set the pointer to the function to be run for the rule (if it is a raw read rule).
void SetInclude(const TString &include)
Set the comma separated list of header files to include to be able to compile this rule.
void AsString(TString &out, const char *options="") const
Add to the string 'out' the string representation of the rule.
const TObjArray * GetSource() const
Get the list of source members as a TObjArray of TNamed object, with the name being the member name a...
void SetReadFunctionPointer(ReadFuncPtr_t ptr)
Set the pointer to the function to be run for the rule (if it is a read rule).
std::vector< UInt_t > * fChecksumVect
Definition: TSchemaRule.h:107
void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
static void ProcessList(TObjArray *array, const TString &list)
Split the list as a comma separated list into a TObjArray of TObjString.
Bool_t operator==(const TSchemaRule &rhs) const
Return true if the rule have the same effects.
Bool_t SetFromRule(const char *rule)
Set the content fot this object from the rule See TClass::AddRule for details on the syntax.
Bool_t TestVersion(Int_t version) const
Check if given version number is defined in this rule.
TString fSource
Target data member vector (for searching purposes)
Definition: TSchemaRule.h:112
Bool_t HasSource(const TString &source) const
Return true if one of the rule's data member source is 'source'.
ReadRawFuncPtr_t GetReadRawFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a raw read rule).
const TObjArray * GetTarget() const
Get the target data members of this rule (i.e. the in memory data member).
Bool_t ProcessChecksum(const TString &checksum) const
Check if specified checksum string is correct and build checksum vector.
void(* ReadFuncPtr_t)(char *, TVirtualObject *)
Definition: TSchemaRule.h:42
void SetEmbed(Bool_t embed)
Set whether this rule should be save in the ROOT file (if true)
RuleType_t GetRuleType() const
Return the type of the rule.
Bool_t Conflicts(const TSchemaRule *rule) const
Check if this rule conflicts with the given one.
TSchemaRule & operator=(const TSchemaRule &rhs)
Copy operator.
void SetTargetClass(const TString &classname)
Set the target class of this rule (i.e. the in memory class).
void(* ReadRawFuncPtr_t)(char *, TBuffer &)
Definition: TSchemaRule.h:43
const char * GetSourceClass() const
Get the source class of this rule (i.e. the onfile class).
virtual ~TSchemaRule()
Destructor.
Bool_t TestChecksum(UInt_t checksum) const
Check if given checksum is defined in this rule.
Bool_t SetVersion(const TString &version)
Set the version string - returns kFALSE if the format is incorrect.
TString fInclude
Source data member vector (for searching purposes)
Definition: TSchemaRule.h:114
TObjArray * fTargetVect
Definition: TSchemaRule.h:111
TString fChecksum
Source version vector (for searching purposes)
Definition: TSchemaRule.h:106
TString fTargetClass
Definition: TSchemaRule.h:109
void SetSource(const TString &source)
Set the list of source members.
Bool_t IsRenameRule() const
Return kTRUE if the rule is a strict renaming of the class to a new name.
void SetAttributes(const TString &attributes)
Set the attributes code of this rule.
TString fSourceClass
Source checksum vector (for searching purposes)
Definition: TSchemaRule.h:108
Bool_t HasTarget(const TString &target) const
Return true if one of the rule's data member target is 'target'.
const char * GetTargetString() const
Get the target data members of this rule as a simple string (i.e. the in memory data member).
std::vector< std::pair< Int_t, Int_t > > * fVersionVect
Definition: TSchemaRule.h:105
ReadRawFuncPtr_t fReadRawFuncPtr
Conversion function pointer for read rule.
Definition: TSchemaRule.h:119
RuleType_t fRuleType
Conversion function pointer for readraw rule.
Definition: TSchemaRule.h:120
Bool_t IsValid() const
Return kTRUE if this rule is valid.
ReadFuncPtr_t GetReadFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a read rule).
const char * GetVersion() const
Get the version string.
const char * GetAttributes() const
Get the attributes code of this rule.
Bool_t GetEmbed() const
Return true if this rule should be saved in the ROOT File.
const char * GetCode() const
Get the source code of this rule.
void SetSourceClass(const TString &classname)
Set the source class of this rule (i.e. the onfile class).
TSchemaRule()
Default Constructor.
Definition: TSchemaRule.cxx:89
Bool_t SetChecksum(const TString &checksum)
Set the checksum string - returns kFALSE if the format is incorrect.
void Clear(Option_t *="")
Zero out this rule object.
const TObjArray * GetInclude() const
Return the list of header files to include to be able to compile this rule as a TObjArray of TObjStri...
Bool_t IsAliasRule() const
Return kTRUE if the rule is a strict renaming of one of the data member of the class.
const char * GetTargetClass() const
Get the targte class of this rule (i.e. the in memory class).
static void ProcessDeclaration(TObjArray *array, const TString &list)
Split the list as a declaration into as a TObjArray of TNamed(name,type).
Bool_t ProcessVersion(const TString &version) const
Check if specified version string is correct and build version vector.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Iterator of object array.
Definition: TObjArray.h:125
TObject * Next()
Return next object in array. Returns 0 when no more objects in array.
Definition: TObjArray.cxx:915
An array of TObjects.
Definition: TObjArray.h:37
Collectable string class.
Definition: TObjString.h:28
const TString & GetString() const
Definition: TObjString.h:47
TString & String()
Definition: TObjString.h:49
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2843
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2851
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2748
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:43
Int_t GetClassVersion() const
std::map< std::string, std::string > MembersMap_t
Definition: TSchemaType.h:20
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"].
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
bool ParseRule(std::string rule, ROOT::Internal::MembersMap_t &result, std::string &error_string)
Parse the schema rule as specified in the LinkDef file.
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
Definition: TClassEdit.cxx:798
static constexpr double second
null_t< F > null()
const char * String
Definition: TXMLSetup.cxx:93