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