Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TROOT.h"
13#include "TSchemaHelper.h"
14
15#include <utility>
16#include <iostream>
17#include <vector>
18#include <list>
19#include <string>
20#include <cstdlib>
21#include <sstream>
22
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 {
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
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)) {
59 continue;
60 }
61 // Check if one string has trailing white space, and the other doesn't.
62 if (*left == null || *right == null) {
65 result = (*left == null && *right == null);
66 break;
67 }
68
69 if (*left != *right) {
70 result = kFALSE;
71 break;
72 }
73
74 if (*left == '"') {
76 }
77 ++left;
78 ++right;
79 }
80 }
81 return result;
82 }
83
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Default Constructor.
88
89TSchemaRule::TSchemaRule(): fVersionVect( nullptr ), fChecksumVect( nullptr ),
90 fTargetVect( nullptr ), fSourceVect( nullptr ),
91 fIncludeVect( nullptr ), fEmbed( kTRUE ),
92 fReadFuncPtr( nullptr ), fReadRawFuncPtr( nullptr ),
93 fRuleType( kNone )
94{
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Constructor.
101 : fVersionVect(nullptr),
102 fChecksumVect(nullptr),
103 fTargetVect(nullptr),
104 fSourceVect(nullptr),
105 fIncludeVect(nullptr),
106 fEmbed(kTRUE),
107 fReadFuncPtr(nullptr),
108 fReadRawFuncPtr(nullptr),
109 fRuleType(type)
110{
111 SetTarget(helper.fTarget);
113 SetSourceClass(helper.fSourceClass);
114 SetSource(helper.fSource);
115 SetCode(helper.fCode);
116 SetVersion(helper.fVersion);
117 SetChecksum(helper.fChecksum);
118 SetEmbed(helper.fEmbed);
119 SetInclude(helper.fInclude);
120 SetAttributes(helper.fAttributes);
121
124 } else {
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Destructor.
131
133{
134 delete fVersionVect;
135 delete fChecksumVect;
136 delete fTargetVect;
137 delete fSourceVect;
138 delete fIncludeVect;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Copy Constructor.
143
145 fVersionVect( nullptr ), fChecksumVect( nullptr ),
146 fTargetVect( nullptr ), fSourceVect( nullptr ),
147 fIncludeVect( nullptr ), fEmbed( kTRUE ),
148 fReadFuncPtr( nullptr ), fReadRawFuncPtr( nullptr ),
149 fRuleType( kNone )
150{
151 *this = rhs;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Copy operator.
156
158{
159 if( this != &rhs ) {
160 fVersion = rhs.fVersion;
161 fChecksum = rhs.fChecksum;
162 fSourceClass = rhs.fSourceClass;
163 fTarget = rhs.fTarget;
164 fSource = rhs.fSource;
165 fInclude = rhs.fInclude;
166 fCode = rhs.fCode;
167 fEmbed = rhs.fEmbed;
168 fReadFuncPtr = rhs.fReadFuncPtr;
169 fReadRawFuncPtr = rhs.fReadRawFuncPtr;
170 fRuleType = rhs.fRuleType;
171 fAttributes = rhs.fAttributes;
172 }
173 return *this;
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Return true if the rule have the same effects.
178
180{
181 if( this != &rhs ) {
182 Bool_t result = ( fVersion == rhs.fVersion
183 && fChecksum == rhs.fChecksum
184 && fSourceClass == rhs.fSourceClass
185 && fTargetClass == rhs.fTargetClass
186 && fSource == rhs.fSource
187 && fTarget == rhs.fTarget
188 && fInclude == rhs.fInclude
189 && IsCodeEquivalent(fCode, rhs.fCode)
190 && fEmbed == rhs.fEmbed
191 && fRuleType == rhs.fRuleType
192 && fAttributes == rhs.fAttributes );
193 if (result &&
194 ( (fReadRawFuncPtr != rhs.fReadRawFuncPtr && fReadRawFuncPtr != nullptr && rhs.fReadRawFuncPtr != nullptr)
195 || (fReadFuncPtr != rhs.fReadFuncPtr && fReadFuncPtr != nullptr && rhs.fReadFuncPtr != nullptr) ) )
196 {
197 result = kFALSE;
198 }
199
200 return result;
201 }
202 return kTRUE;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// The ls function lists the contents of a class on stdout. Ls output
207/// is typically much less verbose then Dump().
208
210{
212 std::cout << "Schema Evolution Rule: ";
213 if (fRuleType==kReadRule) std::cout << "read ";
214 else if (fRuleType==kReadRawRule) std::cout << "readraw ";
215 std::cout << "\n";
218 std::cout << "sourceClass=\"" << fSourceClass << "\" ";
219 if (fVersion.Length()) std::cout << "version=\"" << fVersion << "\" ";
220 if (fChecksum.Length()) std::cout << "checksum=\"" << fChecksum << "\" ";
221 if (targetname && targetname[0]) std::cout << "targetClass=\"" << targetname << "\" ";
222 else std::cout << "targetClass\"" << fTargetClass << "\" ";
223 std::cout << "\n";
225 std::cout << "source=\"" << fSource << "\" ";
226 std::cout << "target=\"" << fTarget << "\" ";
227 std::cout << "\n";
228 if (fInclude.Length()) {
230 std::cout << "include=\"" << fInclude << "\" " << "\n";
231 }
232 if (fAttributes.Length()) {
234 std::cout << "attributes=\"" << fAttributes << "\"" << "\n";
235 }
236 if (fCode.Length()) {
238 std::cout << "code=\"{" << fCode << "}\" "
239 << "\n";
240 }
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Add to the string 'out' the string representation of the rule.
246/// if options contains:
247/// 's' : add the short form of the rule is possible
248/// 'x' : add the xml form of the rule
249
250void TSchemaRule::AsString(TString &out, const char *options) const
251{
252 TString opt(options);
253 opt.ToLower();
254 Bool_t shortform = opt.Contains('s');
255 Bool_t xmlform = opt.Contains('x');
256
257 TString end;
258 if (xmlform) {
259 /*
260 <read sourceClass="ClassA" version="[2]" targetClass="ClassA" source="int m_unit;" target="m_unit" >
261 <![CDATA[ { m_unit = 10*onfile.m_unit; } ]]>
262 </read>
263 */
265 out += "<";
266 if (fRuleType==kReadRule) { out += "read "; end = "</read>"; }
267 else if (fRuleType==kReadRawRule) { out += "readraw "; end = "</readraw>"; }
268 else { out += "-- "; end = "-->"; }
269
270 } else {
271 if (!shortform || fRuleType!=kReadRule) {
272 out += "type=";
273 if (fRuleType==kReadRule) out += "read ";
274 else if (fRuleType==kReadRawRule) out += "readraw ";
275 else out += " ";
276 }
277 }
278 if (!shortform || (fSourceClass != fTargetClass) ) {
279 out += "sourceClass=\"" + fSourceClass + "\" ";
280 out += "targetClass=\"" + fTargetClass + "\" ";
281 } else {
282 out += fSourceClass + " ";
283 }
284 if (shortform && fTarget == fSource) {
285 out += fSource + " ";
286 }
287 if (!shortform || (fVersion != "[1-]")) {
288 if (fVersion.Length()) out += "version=\"" + fVersion + "\" ";
289 }
290 if (fChecksum.Length()) out += "checksum=\"" + fChecksum + "\" ";
291 if (!shortform || fTarget != fSource) {
292 out += "source=\"" + fSource + "\" ";
293 out += "target=\"" + fTarget + "\" ";
294 }
295 if (fInclude.Length()) out += "include=\"" + fInclude + "\" ";
296 if (fAttributes.Length()) out += "attributes=\"" + fAttributes + "\" ";
297 if (xmlform) {
298 out += "> ";
299 }
300 if (xmlform) {
301 if (fCode.Length()) {
302 out += "\n<![CDATA[ { " + fCode + " ]]>\n ";
303 } else if (fReadFuncPtr) {
304 // Can we guess?
305 // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
306 } else if (fReadRawFuncPtr) {
307 // Can we guess?
308 // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";
309 }
310 } else {
311 if (fCode.Length()) {
312 out += "code=\"{" + fCode + "}\" ";
313 } else if (fReadFuncPtr) {
314 // Can we guess?
315 // out += "code=\" + nameof(fReadFuncPtr) + "\" ";
316 } else if (fReadRawFuncPtr) {
317 // Can we guess?
318 // out += "code=\" + nameof(fReadRawFuncPtr) + "\" ";
319 }
320 }
321 if (xmlform) {
322 out += end;
323 }
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Zero out this rule object.
328
329void TSchemaRule::Clear( const char * /* option */)
330{
331 fVersion.Clear();
334 fTarget.Clear();
335 fSource.Clear();
336 fInclude.Clear();
337 fCode.Clear();
339 fReadRawFuncPtr = nullptr;
340 fReadFuncPtr = nullptr;
342 delete fVersionVect; fVersionVect = nullptr;
343 delete fChecksumVect; fChecksumVect = nullptr;
344 delete fTargetVect; fTargetVect = nullptr;
345 delete fSourceVect; fSourceVect = nullptr;
346 delete fIncludeVect; fIncludeVect = nullptr;
347}
348
349////////////////////////////////////////////////////////////////////////////////
350/// Set the content fot this object from the rule
351/// See TClass::AddRule for details on the syntax.
352
354{
355 //-----------------------------------------------------------------------
356 // Parse the rule and check it's validity
357 /////////////////////////////////////////////////////////////////////////////
358
360
361 std::string error_string;
363 Error("SetFromRule","The rule (%s) is invalid: %s",rule,error_string.c_str());
364 return kFALSE;
365 }
366 ROOT::Internal::MembersMap_t::const_iterator it1;
367
368 it1 = rule_values.find( "type" );
369 if( it1 != rule_values.end() ) {
370 if (it1->second == "read" || it1->second == "Read") {
372 } else if (it1->second == "readraw" || it1->second == "ReadRaw") {
374 } else {
376 }
377 } else {
378 // Default to read.
380 }
381 it1 = rule_values.find( "targetClass" );
382 if( it1 != rule_values.end() ) SetTargetClass( it1->second );
383 it1 = rule_values.find( "sourceClass" );
384 if( it1 != rule_values.end() ) SetSourceClass( it1->second );
385 it1 = rule_values.find( "target" );
386 if( it1 != rule_values.end() ) SetTarget( it1->second );
387 it1 = rule_values.find( "source" );
388 if( it1 != rule_values.end() ) SetSource( it1->second );
389 it1 = rule_values.find( "version" );
390 if( it1 != rule_values.end() ) SetVersion( it1->second );
391 it1 = rule_values.find( "checksum" );
392 if( it1 != rule_values.end() ) SetChecksum( it1->second );
393 it1 = rule_values.find( "embed" );
394 if( it1 != rule_values.end() ) SetEmbed( it1->second == "false" ? false : true );
395 it1 = rule_values.find( "include" );
396 if( it1 != rule_values.end() ) SetInclude( it1->second );
397 it1 = rule_values.find( "attributes" );
398 if( it1 != rule_values.end() ) SetAttributes( it1->second );
399 it1 = rule_values.find( "code" );
400 if( it1 != rule_values.end() ) SetCode( it1->second );
401 // if (code is functioname) {
402 // switch (ruleobj->GetRuleType() ) {
403 // case kRead: SetReadFunctionPointer( )
404 // case kReadRewa: SetReadRawFunctionPointer( )
405 // }
406
407 return kTRUE;
408}
409
410////////////////////////////////////////////////////////////////////////////////
411/// Set the version string - returns kFALSE if the format is incorrect
412
414{
415 fVersion = "";
417 if( ret )
419 return ret;
420}
421
422////////////////////////////////////////////////////////////////////////////////
423/// Get the version string.
424
425const char *TSchemaRule::GetVersion() const
426{
427 return fVersion;
428}
429
430
431////////////////////////////////////////////////////////////////////////////////
432/// Check if given version number is defined in this rule
433
435{
436 if( fVersion.IsNull() )
437 return kFALSE;
438
439 if( !fVersionVect )
440 ProcessVersion( fVersion ); // At this point the version string should always be correct
441
442 if (version == -1) {
443 version = 1;
444 }
445
446 if (fVersionVect)
447 for (auto &it : *fVersionVect)
448 if( version >= it.first && version <= it.second )
449 return kTRUE;
450
451 return kFALSE;
452}
453
454////////////////////////////////////////////////////////////////////////////////
455/// Set the checksum string - returns kFALSE if the format is incorrect
456
458{
459 fChecksum = "";
461 if( ret )
463 return ret;
464}
465
466////////////////////////////////////////////////////////////////////////////////
467/// Check if given checksum is defined in this rule
468
470{
471 if( fChecksum.IsNull() )
472 return kFALSE;
473
474 if( !fChecksumVect )
475 ProcessChecksum( fChecksum ); // At this point the checksum string should always be correct
476
477 if (fChecksumVect)
478 for (auto &it : *fChecksumVect)
479 if( checksum == it )
480 return kTRUE;
481
482 return kFALSE;
483}
484
485////////////////////////////////////////////////////////////////////////////////
486/// Set the source class of this rule (i.e. the onfile class).
487
488void TSchemaRule::SetSourceClass( const TString& classname )
489{
490 std::string normalizedName;
493}
494
495////////////////////////////////////////////////////////////////////////////////
496/// Get the source class of this rule (i.e. the onfile class).
497
499{
500 return fSourceClass;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// Set the target class of this rule (i.e. the in memory class).
505
506void TSchemaRule::SetTargetClass( const TString& classname )
507{
508 std::string normalizedName;
511}
512
513////////////////////////////////////////////////////////////////////////////////
514/// Get the targte class of this rule (i.e. the in memory class).
515
517{
518 return fTargetClass;
519}
520
521////////////////////////////////////////////////////////////////////////////////
522/// Set the target member of this rule (i.e. the in memory data member).
523
525{
526 fTarget = target;
527
528 if( target == "" ) {
529 delete fTargetVect;
530 fTargetVect = nullptr;
531 return;
532 }
533
534 if( !fTargetVect ) {
535 fTargetVect = new TObjArray();
537 }
539}
540
541////////////////////////////////////////////////////////////////////////////////
542/// Get the target data members of this rule as a simple string (i.e. the in memory data member).
543
545{
546 return fTarget;
547}
548
549////////////////////////////////////////////////////////////////////////////////
550/// Get the target data members of this rule (i.e. the in memory data member).
551
553{
554 if( fTarget == "" )
555 return nullptr;
556
557 if( !fTargetVect ) {
558 fTargetVect = new TObjArray();
561 }
562
563 return fTargetVect;
564}
565
566////////////////////////////////////////////////////////////////////////////////
567/// Set the list of source members. This should be in the form of a declaration:
568/// Int_t fOldMember; TNamed fName;
569
571{
572 fSource = source;
573
574 if( source == "" ) {
575 delete fSourceVect;
576 fSourceVect = nullptr;
577 return;
578 }
579
580 if( !fSourceVect ) {
581 fSourceVect = new TObjArray();
583 }
584
586}
587
588////////////////////////////////////////////////////////////////////////////////
589/// Get the list of source members as a TObjArray of TNamed object,
590/// with the name being the member name and the title being its type.
591
593{
594 if( fSource == "" )
595 return nullptr;
596
597 if( !fSourceVect ) {
598 fSourceVect = new TObjArray();
601 }
602 return fSourceVect;
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// Set the comma separated list of header files to include to be able
607/// to compile this rule.
608
610{
611 fInclude = incl;
612
613 if( incl == "" ) {
614 delete fIncludeVect;
615 fIncludeVect = nullptr;
616 return;
617 }
618
619 if( !fIncludeVect ) {
620 fIncludeVect = new TObjArray();
622 }
623
625}
626
627////////////////////////////////////////////////////////////////////////////////
628/// Return the list of header files to include to be able to
629/// compile this rule as a TObjArray of TObjString
630
632{
633 if( fInclude == "" )
634 return nullptr;
635
636 if( !fIncludeVect ) {
637 fIncludeVect = new TObjArray();
640 }
641
642 return fIncludeVect;
643}
644
645////////////////////////////////////////////////////////////////////////////////
646/// Set whether this rule should be save in the ROOT file (if true)
647
652
653////////////////////////////////////////////////////////////////////////////////
654/// Return true if this rule should be saved in the ROOT File.
655
657{
658 return fEmbed;
659}
660
661////////////////////////////////////////////////////////////////////////////////
662/// Return kTRUE if this rule is valid.
663
665{
666 return (fVersionVect || fChecksumVect) && (fSourceClass.Length() != 0);
667}
668
669////////////////////////////////////////////////////////////////////////////////
670/// Set the source code of this rule.
671
672void TSchemaRule::SetCode( const TString& code )
673{
674 fCode = code;
675}
676
677////////////////////////////////////////////////////////////////////////////////
678/// Get the source code of this rule.
679
680const char *TSchemaRule::GetCode() const
681{
682 return fCode;
683}
684
685////////////////////////////////////////////////////////////////////////////////
686/// Set the attributes code of this rule.
687
688void TSchemaRule::SetAttributes( const TString& attributes )
689{
690 fAttributes = attributes;
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// Get the attributes code of this rule.
695
696const char *TSchemaRule::GetAttributes() const
697{
698 return fAttributes;
699}
700
701////////////////////////////////////////////////////////////////////////////////
702/// Return true if one of the rule's data member target is 'target'.
703
705{
706 if( !fTargetVect )
707 return kFALSE;
708
709 TObject* obj;
711 while( (obj = it.Next()) ) {
712 TObjString* str = (TObjString*)obj;
713 if( str->GetString() == target )
714 return kTRUE;
715 }
716 return kFALSE;
717}
718
719////////////////////////////////////////////////////////////////////////////////
720/// Return true if one of the rule's data member source is 'source'
721
723{
724 if( !fSourceVect )
725 return kFALSE;
726
727 TObject* obj;
729 while( (obj = it.Next()) ) {
730 TSources* var = (TSources*)obj;
731 if( var->GetName() == source )
732 return kTRUE;
733 }
734 return kFALSE;
735}
736
737////////////////////////////////////////////////////////////////////////////////
738/// Set the pointer to the function to be run for the rule (if it is a read rule).
739
744
745////////////////////////////////////////////////////////////////////////////////
746/// Get the pointer to the function to be run for the rule (if it is a read rule).
747
752
753////////////////////////////////////////////////////////////////////////////////
754/// Set the pointer to the function to be run for the rule (if it is a raw read rule).
755
760
761////////////////////////////////////////////////////////////////////////////////
762/// Get the pointer to the function to be run for the rule (if it is a raw read rule).
763
768
769////////////////////////////////////////////////////////////////////////////////
770/// Set the type of the rule.
771
776
777////////////////////////////////////////////////////////////////////////////////
778/// Return kTRUE if the rule is a strict renaming of one of the data member of the class.
779
781{
782 return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget == "" && fSource == "" && fInclude == "" && fCode == "" && fAttributes == "";
783}
784
785////////////////////////////////////////////////////////////////////////////////
786/// Return kTRUE if the rule is a strict renaming of the class to a new name.
787
789{
790 return fSourceClass != "" && (fVersion != "" || fChecksum != "") && fTarget != "" && fSource != "" && fInclude == "" && fCode == "" && fAttributes == "";
791}
792
793////////////////////////////////////////////////////////////////////////////////
794/// Return the type of the rule.
795
800
801////////////////////////////////////////////////////////////////////////////////
802/// Check if this rule conflicts with the given one.
803
805{
806 //---------------------------------------------------------------------------
807 // If the rules have different sources then the don't conflict
808 /////////////////////////////////////////////////////////////////////////////
809
810 if( fSourceClass != rule->fSourceClass )
811 return kFALSE;
812
813 //---------------------------------------------------------------------------
814 // Check if the rules have common target
815 /////////////////////////////////////////////////////////////////////////////
816
817 if( !rule->GetTarget() )
818 return kFALSE;
819
821 TObjArrayIter titer( rule->GetTarget() );
822 TObjString *str;
823 TObject *obj;
824
825 while( (obj = titer.Next() ) ) {
826 str = (TObjString*)obj;
827 if( HasTarget( str->String() ) )
829 }
830
831 if( !haveCommonTargets )
832 return kFALSE;
833
834 //---------------------------------------------------------------------------
835 // Check if there are conflicting checksums
836 /////////////////////////////////////////////////////////////////////////////
837
838 if( fChecksumVect ) {
839 std::vector<UInt_t>::iterator it;
840 for( it = fChecksumVect->begin(); it != fChecksumVect->end(); ++it )
841 if( rule->TestChecksum( *it ) )
842 return kTRUE;
843 }
844
845 //---------------------------------------------------------------------------
846 // Check if there are conflicting versions
847 /////////////////////////////////////////////////////////////////////////////
848
849 if( fVersionVect && rule->fVersionVect )
850 {
851 std::vector<std::pair<Int_t, Int_t> >::iterator it1;
852 std::vector<std::pair<Int_t, Int_t> >::iterator it2;
853 for( it1 = fVersionVect->begin(); it1 != fVersionVect->end(); ++it1 ) {
854 for( it2 = rule->fVersionVect->begin();
855 it2 != rule->fVersionVect->end(); ++it2 ) {
856 //------------------------------------------------------------------
857 // the rules conflict it their version ranges intersect
858 ////////////////////////////////////////////////////////////////////
859
860 if( it1->first >= it2->first && it1->first <= it2->second )
861 return kTRUE;
862
863 if( it1->first < it2->first && it1->second >= it2->first )
864 return kTRUE;
865 }
866 }
867 }
868 return kFALSE;
869}
870
871////////////////////////////////////////////////////////////////////////////////
872/// Check if specified version string is correct and build version vector.
873
875{
876 //---------------------------------------------------------------------------
877 // Check if we have valid list
878 /////////////////////////////////////////////////////////////////////////////
879
880 if( version[0] != '[' || version[version.Length()-1] != ']' )
881 return kFALSE;
882 std::string ver = version.Data();
883
884 std::list<std::string> versions;
886
887 if( versions.empty() )
888 {
889 delete fVersionVect;
890 fVersionVect = nullptr;
891 return kFALSE;
892 }
893
894 if( !fVersionVect )
895 fVersionVect = new std::vector<std::pair<Int_t, Int_t> >;
896 fVersionVect->clear();
897
898 //---------------------------------------------------------------------------
899 // Check the validity of each list element
900 /////////////////////////////////////////////////////////////////////////////
901
902 std::list<std::string>::iterator it;
903 for( it = versions.begin(); it != versions.end(); ++it ) {
904 std::pair<Int_t, Int_t> verpair;
906 {
907 delete fVersionVect;
908 fVersionVect = nullptr;
909 return kFALSE;
910 }
911 fVersionVect->push_back( verpair );
912 }
913 return kTRUE;
914}
915
916////////////////////////////////////////////////////////////////////////////////
917/// Check if specified checksum string is correct and build checksum vector.
918
920{
921 //---------------------------------------------------------------------------
922 // Check if we have valid list
923 /////////////////////////////////////////////////////////////////////////////
924
925 if (!checksum[0])
926 return kFALSE;
927 std::string chk = (const char*)checksum;
928 if( chk[0] != '[' || chk[chk.size()-1] != ']' )
929 return kFALSE;
930
931 std::list<std::string> checksums;
933
934 if( checksums.empty() ) {
935 delete fChecksumVect;
936 fChecksumVect = nullptr;
937 return kFALSE;
938 }
939
940 if( !fChecksumVect )
941 fChecksumVect = new std::vector<UInt_t>;
942 fChecksumVect->clear();
943
944 //---------------------------------------------------------------------------
945 // Check the validity of each list element
946 /////////////////////////////////////////////////////////////////////////////
947
948 for( const auto& checksumStr : checksums ) {
949 auto chksum = ParseChecksum( checksumStr.c_str() );
950 if (chksum == 0u) {
951 delete fChecksumVect;
952 fChecksumVect = nullptr;
953 return kFALSE;
954 }
955
956 fChecksumVect->push_back( chksum );
957 }
958 return kTRUE;
959}
960
961////////////////////////////////////////////////////////////////////////////////
962/// Parse the checksum in the given string. Returns either the checksum or zero
963/// if the string is not a hex or decimal number.
964
966 std::istringstream converter(checksum);
968 converter >> std::hex >> chksum;
969 if (converter.fail()) {
970 converter.clear();
971 converter.seekg(0);
972 converter >> std::dec >> chksum;
973 }
974
975 if( converter.fail() ) {
976 return 0u;
977 }
978
979 return chksum;
980}
981
982////////////////////////////////////////////////////////////////////////////////
983/// Split the list as a comma separated list into a TObjArray of TObjString.
984
985void TSchemaRule::ProcessList( TObjArray* array, const TString& list )
986{
987 std::list<std::string> elems;
988 std::list<std::string>::iterator it;
989 Internal::TSchemaRuleProcessor::SplitList( (const char*)list, elems );
990
991 array->Clear();
992
993 if( elems.empty() )
994 return;
995
996 for( it = elems.begin(); it != elems.end(); ++it ) {
997 TObjString *str = new TObjString;
998 *str = it->c_str();
999 array->Add( str );
1000 }
1001}
1002
1003////////////////////////////////////////////////////////////////////////////////
1004/// Split the list as a declaration into as a TObjArray of TNamed(name,type).
1005
1007{
1008 std::list<std::pair<ROOT::Internal::TSchemaType,std::string> > elems;
1009 std::list<std::pair<ROOT::Internal::TSchemaType,std::string> >::iterator it;
1010 Internal::TSchemaRuleProcessor::SplitDeclaration( (const char*)list, elems );
1011
1012 array->Clear();
1013
1014 if( elems.empty() )
1015 return;
1016
1017 for( it = elems.begin(); it != elems.end(); ++it ) {
1018 TSources *type = new TSources( it->second.c_str(), it->first.fType.c_str(), it->first.fDimensions.c_str() ) ;
1019 array->Add( type );
1020 }
1021}
1022
1023#if 0
1024////////////////////////////////////////////////////////////////////////////////
1025/// Generate the actual function for the rule.
1026
1027Bool_t TSchemaRule::GenerateFor( TStreamerInfo *info )
1028{
1029 String funcname = fSourceClass + "_to_" + fTargetClass;
1030 if (info) funcname += "_v" + info->GetClassVersion();
1031 TString names = fSource + "_" + fTarget;
1032 name.ReplaceAll(',','_');
1033 name.ReplaceAll(':','_');
1034 funcname += "_" + name;
1035
1036 String filename = funcname + ".C";
1037 if (!false) {
1038 filename += '+';
1039 }
1040
1041 std::ofstream fileout(filename);
1042
1043
1046
1047 gROOT->LoadMacro(filename);
1048}
1049
1050#endif
const Handle_t kNone
Definition GuiTypes.h:88
#define c(i)
Definition RSha256.hxx:101
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:411
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=',')
const_iterator begin() const
const_iterator end() const
void SetRuleType(RuleType_t type)
Set the type of the rule.
TObjArray * fSourceVect
void SetCode(const TString &code)
Set the source code of this rule.
TString fCode
Includes vector.
void SetTarget(const TString &target)
Set the target member of this rule (i.e. the in memory data member).
ReadFuncPtr_t fReadFuncPtr
TObjArray * fIncludeVect
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).
void ls(Option_t *option="") const override
The ls function lists the contents of a class on stdout.
std::vector< UInt_t > * fChecksumVect
UInt_t ParseChecksum(const char *checksum) const
Parse the checksum in the given string.
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.
void Clear(Option_t *="") override
Zero out this rule object.
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)
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:77
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:78
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)
TObjArray * fTargetVect
TString fChecksum
Source version vector (for searching purposes)
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)
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
ReadRawFuncPtr_t fReadRawFuncPtr
Conversion function pointer for read rule.
RuleType_t fRuleType
Conversion function pointer for readraw rule.
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.
Bool_t SetChecksum(const TString &checksum)
Set the checksum string - returns kFALSE if the format is incorrect.
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.
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Iterator of object array.
Definition TObjArray.h:117
TObject * Next() override
Return next object in array. Returns 0 when no more objects in array.
An array of TObjects.
Definition TObjArray.h:31
void Clear(Option_t *option="") override
Remove all objects from the array.
void Add(TObject *obj) override
Definition TObjArray.h:68
Collectable string class.
Definition TObjString.h:28
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition TROOT.cxx:2890
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2898
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition TROOT.cxx:2748
Describes a persistent version of a class.
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
void Clear()
Clear string without changing its capacity.
Definition TString.cxx:1241
Bool_t IsNull() const
Definition TString.h:422
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
std::map< std::string, std::string > MembersMap_t
Definition TSchemaType.h:20
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.
null_t< F > null()