6 #include "RConversionRuleParser.h" 7 #include "TSchemaRuleProcessor.h" 8 #include "TSchemaType.h" 26 static Bool_t IsIrrelevantCharacter(
char c)
28 return (c ==
' ' || c ==
'\n' || c ==
'\t');
31 static void AdvanceOverIrrelevantCharacter(
const char*& str)
33 while (IsIrrelevantCharacter(*str)) {
40 static Bool_t IsCodeEquivalent(
const TString& lhs,
const TString& rhs)
45 const char null =
'\0';
46 const char* left = lhs.Data();
47 const char* right = rhs.Data();
50 AdvanceOverIrrelevantCharacter(left);
51 AdvanceOverIrrelevantCharacter(right);
53 while (*left != null || *right != null) {
55 if (!literal && IsIrrelevantCharacter(*left) && IsIrrelevantCharacter(*right)) {
56 AdvanceOverIrrelevantCharacter(left);
57 AdvanceOverIrrelevantCharacter(right);
61 if (*left == null || *right == null) {
62 AdvanceOverIrrelevantCharacter(left);
63 AdvanceOverIrrelevantCharacter(right);
64 result = (*left == null && *right ==
null);
68 if (*left != *right) {
89 fTargetVect( 0 ), fSourceVect( 0 ),
90 fIncludeVect( 0 ), fEmbed(
kTRUE ),
91 fReadFuncPtr( 0 ), fReadRawFuncPtr( 0 ),
179 std::cout <<
"Schema Evolution Rule: ";
188 if (targetname && targetname[0]) std::cout <<
"targetClass=\"" << targetname <<
"\" ";
189 else std::cout <<
"targetClass\"" <<
fTargetClass <<
"\" ";
192 std::cout <<
"source=\"" <<
fSource <<
"\" ";
193 std::cout <<
"target=\"" <<
fTarget <<
"\" ";
197 std::cout <<
"include=\"" <<
fInclude <<
"\" " <<
"\n";
201 std::cout <<
"attributes=\"" <<
fAttributes <<
"\"" <<
"\n";
203 if (
fCode.Length()) {
205 std::cout <<
"code=\"{" <<
fCode <<
"}\" " 219 TString opt(options);
221 Bool_t shortform = opt.Contains(
's');
222 Bool_t xmlform = opt.Contains(
'x');
235 else { out +=
"-- "; end =
"-->"; }
254 if (!shortform || (
fVersion !=
"[1-]")) {
259 out +=
"source=\"" +
fSource +
"\" ";
260 out +=
"target=\"" +
fTarget +
"\" ";
268 if (
fCode.Length()) {
269 out +=
"\n<![CDATA[ { " +
fCode +
" ]]>\n ";
278 if (
fCode.Length()) {
279 out +=
"code=\"{" +
fCode +
"}\" ";
326 ROOT::Internal::MembersMap_t rule_values;
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());
333 ROOT::Internal::MembersMap_t::const_iterator it1;
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") {
348 it1 = rule_values.find(
"targetClass" );
350 it1 = rule_values.find(
"sourceClass" );
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" );
366 it1 = rule_values.find(
"code" );
367 if( it1 != rule_values.end() )
SetCode( it1->second );
413 std::vector<std::pair<Int_t, Int_t> >::iterator it;
415 if( version >= it->first && version <= it->second )
444 std::vector<UInt_t>::iterator it;
446 if( checksum == *it )
674 while( (obj = it.
Next()) ) {
692 while( (obj = it.
Next()) ) {
788 while( (obj = titer.Next() ) ) {
791 haveCommonTargets =
kTRUE;
794 if( !haveCommonTargets )
802 std::vector<UInt_t>::iterator it;
814 std::vector<std::pair<Int_t, Int_t> >::iterator it1;
815 std::vector<std::pair<Int_t, Int_t> >::iterator it2;
823 if( it1->first >= it2->first && it1->first <= it2->second )
826 if( it1->first < it2->first && it1->second >= it2->first )
843 if( version[0] !=
'[' || version[version.Length()-1] !=
']' )
845 std::string ver = version.Data();
847 std::list<std::string> versions;
848 Internal::TSchemaRuleProcessor::SplitList( ver.substr( 1, ver.size()-2), versions );
850 if( versions.empty() )
858 fVersionVect =
new std::vector<std::pair<Int_t, Int_t> >;
865 std::list<std::string>::iterator it;
866 for( it = versions.begin(); it != versions.end(); ++it ) {
867 std::pair<Int_t, Int_t> verpair;
868 if( !Internal::TSchemaRuleProcessor::ProcessVersion( *it, verpair ) )
890 std::string chk = (
const char*)checksum;
891 if( chk[0] !=
'[' || chk[chk.size()-1] !=
']' )
894 std::list<std::string> checksums;
895 Internal::TSchemaRuleProcessor::SplitList( chk.substr( 1, chk.size()-2), checksums );
897 if( checksums.empty() ) {
911 std::list<std::string>::iterator it;
912 for( it = checksums.begin(); it != checksums.end(); ++it ) {
913 if( !Internal::TSchemaRuleProcessor::IsANumber( *it ) ) {
928 std::list<std::string> elems;
929 std::list<std::string>::iterator it;
930 Internal::TSchemaRuleProcessor::SplitList( (
const char*)list, elems );
937 for( it = elems.begin(); it != elems.end(); ++it ) {
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 );
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() ) ;
973 name.ReplaceAll(
',',
'_');
974 name.ReplaceAll(
':',
'_');
975 funcname +=
"_" +
name;
977 String filename = funcname +
".C";
982 std::ofstream fileout(filename);
985 ROOT::WriteReadRawRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
986 ROOT::WriteReadRuleFunc( *rIt, 0, mappedname, nameTypeMap, fileout );
988 gROOT->LoadMacro(filename);
Describe Streamer information for one class version.
virtual const char * GetName() const
Returns name of object.
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.
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's data member target is 'target'.
void(* ReadRawFuncPtr_t)(char *, TBuffer &)
static Int_t DecreaseDirLevel()
Decrease the indentation level for ls().
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.
Bool_t TestChecksum(UInt_t checksum) const
Check if given checksum is defined in this rule.
Collectable string class.
virtual void Clear(Option_t *option="")
Remove all objects from the array.
ReadRawFuncPtr_t fReadRawFuncPtr
Conversion function pointer for read rule.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual ~TSchemaRule()
Destructor.
Iterator of object array.
TSchemaRule()
Default Constructor.
Bool_t SetVersion(const TString &version)
Set the version string - returns kFALSE if the format is incorrect.
TSchemaRule & operator=(const TSchemaRule &rhs)
Copy operator.
TString fSourceClass
Source checksum vector (for searching purposes)
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.
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
TObject * Next()
Return next object in array. Returns 0 when no more objects in array.
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 'out' 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.
void SetSourceClass(const TString &classname)
Set the source class of this rule (i.e. the onfile class).
ReadFuncPtr_t fReadFuncPtr
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
const char * GetCode() const
Get the source code of this rule.
const char * GetTargetClass() const
Get the targte class of this rule (i.e. the in memory class).
std::vector< UInt_t > * fChecksumVect
void SetTarget(const TString &target)
Set the target member of this rule (i.e. the in memory data member).
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
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.
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)
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)
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 *)
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's data member source is 'source'.
void SetEmbed(Bool_t embed)
Set whether this rule should be save in the ROOT file (if true)
Mother of all ROOT objects.
static Int_t IncreaseDirLevel()
Increase the indentation level for ls().
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)
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).
Bool_t IsAliasRule() const
Return kTRUE if the rule is a strict renaming of one of the data member of the class.
void SetRuleType(RuleType_t type)
Set the type of the rule.
ReadFuncPtr_t GetReadFunctionPointer() const
Get the pointer to the function to be run for the rule (if it is a read rule).
Bool_t SetFromRule(const char *rule)
Set the content fot this object from the rule See TClass::AddRule for details on the syntax...