Logo ROOT  
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"
8 #include "TSchemaRuleProcessor.h"
9 #include "TSchemaType.h"
10 #include "TObjArray.h"
11 #include "TObjString.h"
12 #include "TROOT.h"
13 
14 #include <utility>
15 #include <iostream>
16 #include <vector>
17 #include <list>
18 #include <string>
19 #include <cstdlib>
20 #include <sstream>
21 
23 
24 using namespace ROOT;
25 
26 namespace {
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 
89 TSchemaRule::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;
139  fAttributes = rhs.fAttributes;
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 &&
162  ( (fReadRawFuncPtr != rhs.fReadRawFuncPtr && fReadRawFuncPtr != 0 && rhs.fReadRawFuncPtr != 0)
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 
177 void 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 
218 void 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 
297 void TSchemaRule::Clear( const char * /* option */)
298 {
299  fVersion.Clear();
300  fChecksum.Clear();
302  fTarget.Clear();
303  fSource.Clear();
304  fInclude.Clear();
305  fCode.Clear();
306  fAttributes.Clear();
307  fReadRawFuncPtr = 0;
308  fReadFuncPtr = 0;
309  fRuleType = kNone;
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 
321 Bool_t TSchemaRule::SetFromRule( const char *rule )
322 {
323  //-----------------------------------------------------------------------
324  // Parse the rule and check it's validity
325  /////////////////////////////////////////////////////////////////////////////
326 
327  ROOT::Internal::MembersMap_t rule_values;
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 
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 
393 const 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 
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 
456 void 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 
466 const char *TSchemaRule::GetSourceClass() const
467 {
468  return fSourceClass;
469 }
470 
471 ////////////////////////////////////////////////////////////////////////////////
472 /// Set the target class of this rule (i.e. the in memory class).
473 
474 void 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 
484 const char *TSchemaRule::GetTargetClass() const
485 {
486  return fTargetClass;
487 }
488 
489 ////////////////////////////////////////////////////////////////////////////////
490 /// Set the target member of this rule (i.e. the in memory data member).
491 
492 void 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 
512 const char *TSchemaRule::GetTargetString() const
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 
538 void 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 
553  ProcessDeclaration( fSourceVect, source );
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 
577 void 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 
640 void TSchemaRule::SetCode( const TString& code )
641 {
642  fCode = code;
643 }
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// Get the source code of this rule.
647 
648 const char *TSchemaRule::GetCode() const
649 {
650  return fCode;
651 }
652 
653 ////////////////////////////////////////////////////////////////////////////////
654 /// Set the attributes code of this rule.
655 
656 void TSchemaRule::SetAttributes( const TString& attributes )
657 {
658  fAttributes = attributes;
659 }
660 
661 ////////////////////////////////////////////////////////////////////////////////
662 /// Get the attributes code of this rule.
663 
664 const 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 
672 Bool_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 
690 Bool_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 
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 
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  for( const auto& checksumStr : checksums ) {
917  auto chksum = ParseChecksum( checksumStr.c_str() );
918  if (chksum == 0u) {
919  delete fChecksumVect;
920  fChecksumVect = nullptr;
921  return kFALSE;
922  }
923 
924  fChecksumVect->push_back( chksum );
925  }
926  return kTRUE;
927 }
928 
929 ////////////////////////////////////////////////////////////////////////////////
930 /// Parse the checksum in the given string. Returns either the checksum or zero
931 /// if the string is not a hex or decimal number.
932 
933 UInt_t TSchemaRule::ParseChecksum(const char* checksum) const {
934  std::istringstream converter(checksum);
935  UInt_t chksum;
936  converter >> std::hex >> chksum;
937  if (converter.fail()) {
938  converter.clear();
939  converter.seekg(0);
940  converter >> std::dec >> chksum;
941  }
942 
943  if( converter.fail() ) {
944  return 0u;
945  }
946 
947  return chksum;
948 }
949 
950 ////////////////////////////////////////////////////////////////////////////////
951 /// Split the list as a comma separated list into a TObjArray of TObjString.
952 
953 void TSchemaRule::ProcessList( TObjArray* array, const TString& list )
954 {
955  std::list<std::string> elems;
956  std::list<std::string>::iterator it;
957  Internal::TSchemaRuleProcessor::SplitList( (const char*)list, elems );
958 
959  array->Clear();
960 
961  if( elems.empty() )
962  return;
963 
964  for( it = elems.begin(); it != elems.end(); ++it ) {
965  TObjString *str = new TObjString;
966  *str = it->c_str();
967  array->Add( str );
968  }
969 }
970 
971 ////////////////////////////////////////////////////////////////////////////////
972 /// Split the list as a declaration into as a TObjArray of TNamed(name,type).
973 
975 {
976  std::list<std::pair<ROOT::Internal::TSchemaType,std::string> > elems;
977  std::list<std::pair<ROOT::Internal::TSchemaType,std::string> >::iterator it;
978  Internal::TSchemaRuleProcessor::SplitDeclaration( (const char*)list, elems );
979 
980  array->Clear();
981 
982  if( elems.empty() )
983  return;
984 
985  for( it = elems.begin(); it != elems.end(); ++it ) {
986  TSources *type = new TSources( it->second.c_str(), it->first.fType.c_str(), it->first.fDimensions.c_str() ) ;
987  array->Add( type );
988  }
989 }
990 
991 #if 0
992 ////////////////////////////////////////////////////////////////////////////////
993 /// Generate the actual function for the rule.
994 
995 Bool_t TSchemaRule::GenerateFor( TStreamerInfo *info )
996 {
997  String funcname = fSourceClass + "_to_" + fTargetClass;
998  if (info) funcname += "_v" + info->GetClassVersion();
999  TString names = fSource + "_" + fTarget;
1000  name.ReplaceAll(',','_');
1001  name.ReplaceAll(':','_');
1002  funcname += "_" + name;
1003 
1004  String filename = funcname + ".C";
1005  if (!false) {
1006  filename += '+';
1007  }
1008 
1009  std::ofstream fileout(filename);
1010 
1011 
1012  ROOT::WriteReadRawRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
1013  ROOT::WriteReadRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
1014 
1015  gROOT->LoadMacro(filename);
1016 }
1017 
1018 #endif
c
#define c(i)
Definition: RSha256.hxx:119
ROOT::ParseRule
bool ParseRule(std::string rule, ROOT::Internal::MembersMap_t &result, std::string &error_string)
Parse the schema rule as specified in the LinkDef file.
Definition: RConversionRuleParser.cxx:103
ROOT::TSchemaRule::SetReadFunctionPointer
void SetReadFunctionPointer(ReadFuncPtr_t ptr)
Set the pointer to the function to be run for the rule (if it is a read rule).
Definition: TSchemaRule.cxx:708
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
ROOT::TSchemaRule::HasSource
Bool_t HasSource(const TString &source) const
Return true if one of the rule's data member source is 'source'.
Definition: TSchemaRule.cxx:690
TObjArray
Definition: TObjArray.h:37
TClassEdit::GetNormalizedName
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
Definition: TClassEdit.cxx:831
ROOT::TSchemaRule::fVersion
TString fVersion
Definition: TSchemaRule.h:103
ROOT::TSchemaRule::ProcessChecksum
Bool_t ProcessChecksum(const TString &checksum) const
Check if specified checksum string is correct and build checksum vector.
Definition: TSchemaRule.cxx:887
ROOT::TSchemaRule::GetTarget
const TObjArray * GetTarget() const
Get the target data members of this rule (i.e. the in memory data member).
Definition: TSchemaRule.cxx:520
TROOT::DecreaseDirLevel
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
Definition: TROOT.cxx:2696
ROOT::TSchemaRule::ProcessList
static void ProcessList(TObjArray *array, const TString &list)
Split the list as a comma separated list into a TObjArray of TObjString.
Definition: TSchemaRule.cxx:953
ROOT::TSchemaRule::fInclude
TString fInclude
Source data member vector (for searching purposes)
Definition: TSchemaRule.h:113
ROOT::TSchemaRule::TSchemaRule
TSchemaRule()
Default Constructor.
Definition: TSchemaRule.cxx:89
ROOT::TSchemaRule::GetInclude
const TObjArray * GetInclude() const
Return the list of header files to include to be able to compile this rule as a TObjArray of TObjStri...
Definition: TSchemaRule.cxx:599
TString::Data
const char * Data() const
Definition: TString.h:369
ROOT::TSchemaRule::ProcessVersion
Bool_t ProcessVersion(const TString &version) const
Check if specified version string is correct and build version vector.
Definition: TSchemaRule.cxx:842
ROOT::TSchemaRule::fEmbed
Bool_t fEmbed
Definition: TSchemaRule.h:116
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
ROOT::TSchemaRule::fSourceClass
TString fSourceClass
Source checksum vector (for searching purposes)
Definition: TSchemaRule.h:107
TObjString.h
ROOT::TSchemaRule::GetSourceClass
const char * GetSourceClass() const
Get the source class of this rule (i.e. the onfile class).
Definition: TSchemaRule.cxx:466
ROOT::TSchemaRule::GetSource
const TObjArray * GetSource() const
Get the list of source members as a TObjArray of TNamed object, with the name being the member name a...
Definition: TSchemaRule.cxx:560
ROOT::TSchemaRule::TestVersion
Bool_t TestVersion(Int_t version) const
Check if given version number is defined in this rule.
Definition: TSchemaRule.cxx:402
ROOT::TSchemaRule::SetTargetClass
void SetTargetClass(const TString &classname)
Set the target class of this rule (i.e. the in memory class).
Definition: TSchemaRule.cxx:474
ROOT::WriteReadRawRuleFunc
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"...
Definition: RConversionRuleParser.cxx:694
TSchemaType.h
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
ROOT::TSchemaRule::fRuleType
RuleType_t fRuleType
Conversion function pointer for readraw rule.
Definition: TSchemaRule.h:119
TCollection::SetOwner
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Definition: TCollection.cxx:746
ROOT::TSchemaRule::ReadFuncPtr_t
void(* ReadFuncPtr_t)(char *, TVirtualObject *)
Definition: TSchemaRule.h:40
ROOT::TSchemaRule::IsAliasRule
Bool_t IsAliasRule() const
Return kTRUE if the rule is a strict renaming of one of the data member of the class.
Definition: TSchemaRule.cxx:748
ROOT::TSchemaRule::fReadRawFuncPtr
ReadRawFuncPtr_t fReadRawFuncPtr
Conversion function pointer for read rule.
Definition: TSchemaRule.h:118
TObjString::GetString
const TString & GetString() const
Definition: TObjString.h:52
TString::Contains
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
ROOT::TSchemaRule::SetTarget
void SetTarget(const TString &target)
Set the target member of this rule (i.e. the in memory data member).
Definition: TSchemaRule.cxx:492
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
ROOT::TSchemaRule::SetFromRule
Bool_t SetFromRule(const char *rule)
Set the content fot this object from the rule See TClass::AddRule for details on the syntax.
Definition: TSchemaRule.cxx:321
TString
Definition: TString.h:136
ROOT::TSchemaRule::ls
void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition: TSchemaRule.cxx:177
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
RConversionRuleParser.h
TObjArrayIter
Definition: TObjArray.h:123
TString::Clear
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1176
ROOT::TSchemaRule::kReadRawRule
@ kReadRawRule
Definition: TSchemaRule.h:36
ROOT::TSchemaRule::ReadRawFuncPtr_t
void(* ReadRawFuncPtr_t)(char *, TBuffer &)
Definition: TSchemaRule.h:41
bool
ROOT::TSchemaRule::SetVersion
Bool_t SetVersion(const TString &version)
Set the version string - returns kFALSE if the format is incorrect.
Definition: TSchemaRule.cxx:381
ROOT::TSchemaRule::kNone
@ kNone
Definition: TSchemaRule.h:37
TObjArray::Add
void Add(TObject *obj)
Definition: TObjArray.h:74
ROOT::TSchemaRule::SetSource
void SetSource(const TString &source)
Set the list of source members.
Definition: TSchemaRule.cxx:538
TObjString::String
TString & String()
Definition: TObjString.h:54
ROOT::TSchemaRule::RuleType_t
RuleType_t
Definition: TSchemaRule.h:33
TROOT.h
TObjString
Definition: TObjString.h:28
ROOT::TSchemaRule
Definition: TSchemaRule.h:19
ROOT::Internal::TSchemaRuleProcessor::ProcessVersion
static bool ProcessVersion(const std::string &source, std::pair< Int_t, Int_t > &result)
Definition: TSchemaRuleProcessor.h:158
TSchemaRuleProcessor.h
ROOT::TSchemaRule::fIncludeVect
TObjArray * fIncludeVect
Definition: TSchemaRule.h:114
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TSchemaRule.h
ROOT::TSchemaRule::fTargetClass
TString fTargetClass
Definition: TSchemaRule.h:108
ROOT::TSchemaRule::SetChecksum
Bool_t SetChecksum(const TString &checksum)
Set the checksum string - returns kFALSE if the format is incorrect.
Definition: TSchemaRule.cxx:425
ROOT::TSchemaRule::AsString
void AsString(TString &out, const char *options="") const
Add to the string 'out' the string representation of the rule.
Definition: TSchemaRule.cxx:218
ROOT::TSchemaRule::fChecksumVect
std::vector< UInt_t > * fChecksumVect
Definition: TSchemaRule.h:106
TStreamerInfo
Definition: TStreamerInfo.h:44
ROOT::TSchemaRule::GetVersion
const char * GetVersion() const
Get the version string.
Definition: TSchemaRule.cxx:393
ROOT::TSchemaRule::~TSchemaRule
virtual ~TSchemaRule()
Destructor.
Definition: TSchemaRule.cxx:100
ROOT::TSchemaRule::SetSourceClass
void SetSourceClass(const TString &classname)
Set the source class of this rule (i.e. the onfile class).
Definition: TSchemaRule.cxx:456
ROOT::TSchemaRule::Clear
void Clear(Option_t *="")
Zero out this rule object.
Definition: TSchemaRule.cxx:297
ROOT::TSchemaRule::fSource
TString fSource
Target data member vector (for searching purposes)
Definition: TSchemaRule.h:111
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
ROOT::TSchemaRule::HasTarget
Bool_t HasTarget(const TString &target) const
Return true if one of the rule's data member target is 'target'.
Definition: TSchemaRule.cxx:672
xmlio::String
const char * String
Definition: TXMLSetup.cxx:100
ROOT::TSchemaRule::GetReadRawFunctionPointer
ReadRawFuncPtr_t GetReadRawFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a raw read rule).
Definition: TSchemaRule.cxx:732
ROOT::TSchemaRule::GetEmbed
Bool_t GetEmbed() const
Return true if this rule should be saved in the ROOT File.
Definition: TSchemaRule.cxx:624
ROOT::TSchemaRule::TestChecksum
Bool_t TestChecksum(UInt_t checksum) const
Check if given checksum is defined in this rule.
Definition: TSchemaRule.cxx:437
ROOT::TSchemaRule::GetTargetString
const char * GetTargetString() const
Get the target data members of this rule as a simple string (i.e. the in memory data member).
Definition: TSchemaRule.cxx:512
ROOT::TSchemaRule::ParseChecksum
UInt_t ParseChecksum(const char *checksum) const
Parse the checksum in the given string.
Definition: TSchemaRule.cxx:933
TROOT::IncreaseDirLevel
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
Definition: TROOT.cxx:2792
ROOT::TSchemaRule::SetAttributes
void SetAttributes(const TString &attributes)
Set the attributes code of this rule.
Definition: TSchemaRule.cxx:656
TROOT::IndentLevel
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2800
ROOT::WriteReadRuleFunc
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"].
Definition: RConversionRuleParser.cxx:641
unsigned int
TStreamerInfo::GetClassVersion
Int_t GetClassVersion() const
Definition: TStreamerInfo.h:208
ROOT::TSchemaRule::kReadRule
@ kReadRule
Definition: TSchemaRule.h:35
TObjArray::Clear
virtual void Clear(Option_t *option="")
Remove all objects from the array.
Definition: TObjArray.cxx:321
ROOT::TSchemaRule::fChecksum
TString fChecksum
Source version vector (for searching purposes)
Definition: TSchemaRule.h:105
ROOT::TSchemaRule::SetCode
void SetCode(const TString &code)
Set the source code of this rule.
Definition: TSchemaRule.cxx:640
ROOT::TSchemaRule::TSources
Definition: TSchemaRule.h:23
ROOT::TSchemaRule::operator==
Bool_t operator==(const TSchemaRule &rhs) const
Return true if the rule have the same effects.
Definition: TSchemaRule.cxx:147
ROOT::TSchemaRule::GetAttributes
const char * GetAttributes() const
Get the attributes code of this rule.
Definition: TSchemaRule.cxx:664
TObjArray.h
TClassEdit.h
ROOT::TSchemaRule::fSourceVect
TObjArray * fSourceVect
Definition: TSchemaRule.h:112
ROOT::TSchemaRule::ProcessDeclaration
static void ProcessDeclaration(TObjArray *array, const TString &list)
Split the list as a declaration into as a TObjArray of TNamed(name,type).
Definition: TSchemaRule.cxx:974
ROOT::TSchemaRule::fReadFuncPtr
ReadFuncPtr_t fReadFuncPtr
Definition: TSchemaRule.h:117
TObject
Definition: TObject.h:37
ROOT::TSchemaRule::SetInclude
void SetInclude(const TString &include)
Set the comma separated list of header files to include to be able to compile this rule.
Definition: TSchemaRule.cxx:577
name
char name[80]
Definition: TGX11.cxx:110
ROOT::TSchemaRule::GetCode
const char * GetCode() const
Get the source code of this rule.
Definition: TSchemaRule.cxx:648
ROOT::TSchemaRule::GetTargetClass
const char * GetTargetClass() const
Get the targte class of this rule (i.e. the in memory class).
Definition: TSchemaRule.cxx:484
ROOT::TSchemaRule::SetRuleType
void SetRuleType(RuleType_t type)
Set the type of the rule.
Definition: TSchemaRule.cxx:740
ROOT::Internal::TSchemaRuleProcessor::SplitDeclaration
static void SplitDeclaration(const std::string &source, std::list< std::pair< ROOT::Internal::TSchemaType, std::string > > &result)
Definition: TSchemaRuleProcessor.h:56
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
type
int type
Definition: TGX11.cxx:121
ROOT::TSchemaRule::IsValid
Bool_t IsValid() const
Return kTRUE if this rule is valid.
Definition: TSchemaRule.cxx:632
ROOT::TSchemaRule::fVersionVect
std::vector< std::pair< Int_t, Int_t > > * fVersionVect
Definition: TSchemaRule.h:104
TObjArrayIter::Next
TObject * Next()
Return next object in array. Returns 0 when no more objects in array.
Definition: TObjArray.cxx:931
ROOT::TSchemaRule::SetEmbed
void SetEmbed(Bool_t embed)
Set whether this rule should be save in the ROOT file (if true)
Definition: TSchemaRule.cxx:616
TString::ToLower
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1125
ROOT::TSchemaRule::fCode
TString fCode
Includes vector.
Definition: TSchemaRule.h:115
ROOT::TSchemaRule::GetReadFunctionPointer
ReadFuncPtr_t GetReadFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a read rule).
Definition: TSchemaRule.cxx:716
ROOT::Internal::MembersMap_t
std::map< std::string, std::string > MembersMap_t
Definition: TSchemaType.h:20
ROOT::TSchemaRule::GetRuleType
RuleType_t GetRuleType() const
Return the type of the rule.
Definition: TSchemaRule.cxx:764
TGeant4Unit::second
static constexpr double second
Definition: TGeant4SystemOfUnits.h:157
ROOT::TSchemaRule::fTargetVect
TObjArray * fTargetVect
Definition: TSchemaRule.h:110
ROOT::TSchemaRule::Conflicts
Bool_t Conflicts(const TSchemaRule *rule) const
Check if this rule conflicts with the given one.
Definition: TSchemaRule.cxx:772
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::TSchemaRule::SetReadRawFunctionPointer
void SetReadRawFunctionPointer(ReadRawFuncPtr_t ptr)
Set the pointer to the function to be run for the rule (if it is a raw read rule).
Definition: TSchemaRule.cxx:724
ROOT::TSchemaRule::fTarget
TString fTarget
Definition: TSchemaRule.h:109
ROOT::TSchemaRule::fAttributes
TString fAttributes
Definition: TSchemaRule.h:120
gROOT
#define gROOT
Definition: TROOT.h:406
ROOT::TSchemaRule::operator=
TSchemaRule & operator=(const TSchemaRule &rhs)
Copy operator.
Definition: TSchemaRule.cxx:125
int
ROOT::TSchemaRule::IsRenameRule
Bool_t IsRenameRule() const
Return kTRUE if the rule is a strict renaming of the class to a new name.
Definition: TSchemaRule.cxx:756
ROOT::Internal::TSchemaRuleProcessor::SplitList
static void SplitList(const std::string &source, std::list< std::string > &result, char delimiter=',')
Definition: TSchemaRuleProcessor.h:26