Logo ROOT  
Reference Guide
BaseSelectionRule.h
Go to the documentation of this file.
1 // @(#)root/core/utils:$Id: BaseSelectionRule.h 28529 2009-05-11 16:43:35Z pcanal $
2 // Author: Velislava Spasova September 2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, Rene Brun, Fons Rademakers and al. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef R__BASESELECTIONRULE_H
13 #define R__BASESELECTIONRULE_H
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // BaseSelectionRule //
18 // //
19 // Base selection class from which all //
20 // selection classes should be derived //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include <string>
25 #include <unordered_map>
26 #include <list>
27 #include <iosfwd>
28 
29 namespace clang {
30  class NamedDecl;
31  class CXXRecordDecl;
32  class Type;
33 }
34 namespace cling {
35  class Interpreter;
36 }
37 
39 {
40 public:
41  typedef std::unordered_map<std::string, std::string> AttributesMap_t; // The liste of selection rule's attributes (name, pattern, ...)
42 
43  enum ESelect { // a rule could be selected, vetoed or we don't care about it
45  kNo,
47  };
48  enum EMatchType {
53  };
54 
55 private:
56  long fIndex; // Index indicating the ordering of the rules.
57  long fLineNumber=-1; // Line number of the selection file where the rule is located
58  std::string fSelFileName=""; // Name of the selection file
59  AttributesMap_t fAttributes; // list of the attributes of the selection/exclusion rule
60  ESelect fIsSelected; // selected/vetoed/don't care
61  std::list<std::string> fSubPatterns; // a list of subpatterns, generated form a pattern/proto_pattern attribute
62  std::list<std::string> fFileSubPatterns; // a list of subpatterns, generated form a file_pattern attribute
63  bool fMatchFound; // this is true if this selection rule has been used at least once
64  const clang::CXXRecordDecl *fCXXRecordDecl; // Record decl of the entity searched for.
65  const clang::Type *fRequestedType; // Same as the record decl but with some of the typedef preserved (Double32_t, Float16_t, etc..)
66  cling::Interpreter *fInterp;
67 
68  // Cached for performance
69  std::string fName = "";
70  std::string fPattern = "";
71  std::string fProtoName = "";
72  std::string fProtoPattern = "";
73  std::string fFileName = "";
74  std::string fFilePattern = "";
75  std::string fNArgsToKeep = "";
76  bool fHasNameAttribute = false;
77  bool fHasProtoNameAttribute = false;
78  bool fHasPatternAttribute = false;
80  bool fHasFileNameAttribute = false;
83  bool fIsFromTypedef = false;
84 
85 public:
86 
88 
89  BaseSelectionRule(long index, cling::Interpreter &interp, const char* selFileName = "", long lineno=-1) : fIndex(index),fLineNumber(lineno),fSelFileName(selFileName),fIsSelected(kNo),fMatchFound(false),fCXXRecordDecl(0),fRequestedType(0),fInterp(&interp) {}
90 
91  BaseSelectionRule(long index, ESelect sel, const std::string& attributeName, const std::string& attributeValue, cling::Interpreter &interp, const char* selFileName = "",long lineno=-1);
92 
93  virtual ~BaseSelectionRule() = default;
94 
95  virtual void DebugPrint() const;
96  virtual void Print(std::ostream &out) const = 0;
97 
98  long GetIndex() const { return fIndex; }
99  void SetIndex(long index) { fIndex=index; }
100 
101  long GetLineNumber() const { return fLineNumber; }
102  const char* GetSelFileName() const { return fSelFileName.c_str(); }
103 
104  bool HasAttributeWithName(const std::string& attributeName) const; // returns true if there is an attribute with the specified name
105 
106  void FillCache(); // Fill the cache for performant attribute retrival
107 
108  bool GetAttributeValue(const std::string& attributeName, std::string& returnValue) const; // returns the value of the attribute with name attributeName
109 
110  inline const std::string& GetAttributeName() const {return fName;};
111  inline bool HasAttributeName() const {return fHasNameAttribute;};
112 
113  inline const std::string& GetAttributeProtoName() const {return fProtoName;};
114  inline bool HasAttributeProtoName() const {return fHasProtoNameAttribute;};
115 
116  inline const std::string& GetAttributePattern() const {return fPattern;};
117  inline bool HasAttributePattern() const {return fHasPatternAttribute;};
118 
119  inline const std::string& GetAttributeProtoPattern() const {return fProtoPattern;};
121 
122  inline const std::string& GetAttributeFileName() const {return fFileName;};
123  inline bool HasAttributeFileName() const {return fHasFileNameAttribute;};
124 
125  inline const std::string& GetAttributeFilePattern() const {return fFilePattern;};
126  inline bool HasAttributeFilePattern() const {return fHasFilePatternAttribute;};
127 
128  inline bool IsFromTypedef() const {return fIsFromTypedef;};
129  inline bool HasAttributeFromTypedef() const {return fHasFromTypedefAttribute;};
130 
131  inline const std::string& GetAttributeNArgsToKeep() const {return fNArgsToKeep;};
132 
133  void SetAttributeValue(const std::string& attributeName, const std::string& attributeValue); // sets an attribute with name attribute name and value attributeValue
134 
135  ESelect GetSelected() const;
136  void SetSelected(ESelect sel);
137 
138  bool HasInterpreter() const {return fInterp!=NULL; };
139  void SetInterpreter(cling::Interpreter& interp) {fInterp=&interp; };
140 
141  const AttributesMap_t& GetAttributes() const; // returns the list of attributes
142  void PrintAttributes(int level) const; // prints the list of attributes - level is the number of tabs from the beginning of the line
143  void PrintAttributes(std::ostream &out, int level) const; // prints the list of attributes - level is the number of tabs from the beginning of the line
144 
145  EMatchType Match(const clang::NamedDecl *decl, const std::string& name, const std::string& prototype, bool isLinkdef) const; // for more detailed description look at the .cxx file
146 
147  void SetMatchFound(bool match); // set fMatchFound
148  bool GetMatchFound() const; // get fMatchFound
149 
150  const clang::Type *GetRequestedType() const;
151  inline const clang::CXXRecordDecl *GetCXXRecordDecl() const {return fCXXRecordDecl;} ;
152  void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr);
153 
154 protected:
155 
156  // Checks if the test string matches against the pattern (which has produced the list of sub-patterns patterns_list). There is
157  // difference if we are processing linkdef.h or selection.xmlpatterns
158  inline bool CheckPattern(const std::string& test, const std::string& pattern, const std::list<std::string>& patterns_list, bool isLinkdef) const;
159 
160  inline void ProcessPattern(const std::string& pattern, std::list<std::string>& out) const; // divides a pattern into a list of sub-patterns
161 };
162 
163 inline std::ostream &operator<<(std::ostream& out, const BaseSelectionRule &obj)
164 {
165  obj.Print(out);
166  return out;
167 }
168 #endif
BaseSelectionRule::GetAttributeProtoPattern
const std::string & GetAttributeProtoPattern() const
Definition: BaseSelectionRule.h:119
BaseSelectionRule::GetAttributeNArgsToKeep
const std::string & GetAttributeNArgsToKeep() const
Definition: BaseSelectionRule.h:131
BaseSelectionRule::SetInterpreter
void SetInterpreter(cling::Interpreter &interp)
Definition: BaseSelectionRule.h:139
BaseSelectionRule::EMatchType
EMatchType
Definition: BaseSelectionRule.h:48
BaseSelectionRule::fName
std::string fName
Definition: BaseSelectionRule.h:69
BaseSelectionRule::BaseSelectionRule
BaseSelectionRule(long index, cling::Interpreter &interp, const char *selFileName="", long lineno=-1)
Definition: BaseSelectionRule.h:89
BaseSelectionRule::fFileName
std::string fFileName
Definition: BaseSelectionRule.h:73
BaseSelectionRule::HasAttributeProtoName
bool HasAttributeProtoName() const
Definition: BaseSelectionRule.h:114
BaseSelectionRule::ProcessPattern
void ProcessPattern(const std::string &pattern, std::list< std::string > &out) const
Definition: BaseSelectionRule.cxx:373
BaseSelectionRule::fFileSubPatterns
std::list< std::string > fFileSubPatterns
Definition: BaseSelectionRule.h:62
BaseSelectionRule::GetAttributeFilePattern
const std::string & GetAttributeFilePattern() const
Definition: BaseSelectionRule.h:125
BaseSelectionRule::GetSelected
ESelect GetSelected() const
Definition: BaseSelectionRule.cxx:103
BaseSelectionRule::~BaseSelectionRule
virtual ~BaseSelectionRule()=default
BaseSelectionRule::GetMatchFound
bool GetMatchFound() const
Definition: BaseSelectionRule.cxx:523
BaseSelectionRule::fHasProtoPatternAttribute
bool fHasProtoPatternAttribute
Definition: BaseSelectionRule.h:79
BaseSelectionRule::kNo
@ kNo
Definition: BaseSelectionRule.h:45
BaseSelectionRule::fIsFromTypedef
bool fIsFromTypedef
Definition: BaseSelectionRule.h:83
BaseSelectionRule::fSubPatterns
std::list< std::string > fSubPatterns
Definition: BaseSelectionRule.h:61
BaseSelectionRule::Print
virtual void Print(std::ostream &out) const =0
BaseSelectionRule::fIsSelected
ESelect fIsSelected
Definition: BaseSelectionRule.h:60
BaseSelectionRule::FillCache
void FillCache()
Definition: BaseSelectionRule.cxx:539
BaseSelectionRule::GetAttributeFileName
const std::string & GetAttributeFileName() const
Definition: BaseSelectionRule.h:122
ROOT::Math::IntegrationOneDim::Type
Type
enumeration specifying the integration types.
Definition: AllIntegrationTypes.h:60
test
Definition: test.py:1
BaseSelectionRule::HasAttributePattern
bool HasAttributePattern() const
Definition: BaseSelectionRule.h:117
BaseSelectionRule::fRequestedType
const clang::Type * fRequestedType
Definition: BaseSelectionRule.h:65
BaseSelectionRule::fFilePattern
std::string fFilePattern
Definition: BaseSelectionRule.h:74
BaseSelectionRule::HasAttributeFilePattern
bool HasAttributeFilePattern() const
Definition: BaseSelectionRule.h:126
BaseSelectionRule::kFile
@ kFile
Definition: BaseSelectionRule.h:51
BaseSelectionRule::HasAttributeFromTypedef
bool HasAttributeFromTypedef() const
Definition: BaseSelectionRule.h:129
BaseSelectionRule::PrintAttributes
void PrintAttributes(int level) const
Definition: BaseSelectionRule.cxx:178
BaseSelectionRule::GetSelFileName
const char * GetSelFileName() const
Definition: BaseSelectionRule.h:102
BaseSelectionRule::GetRequestedType
const clang::Type * GetRequestedType() const
Definition: BaseSelectionRule.cxx:528
BaseSelectionRule::IsFromTypedef
bool IsFromTypedef() const
Definition: BaseSelectionRule.h:128
BaseSelectionRule::CheckPattern
bool CheckPattern(const std::string &test, const std::string &pattern, const std::list< std::string > &patterns_list, bool isLinkdef) const
Definition: BaseSelectionRule.cxx:445
BaseSelectionRule::GetAttributePattern
const std::string & GetAttributePattern() const
Definition: BaseSelectionRule.h:116
BaseSelectionRule::HasInterpreter
bool HasInterpreter() const
Definition: BaseSelectionRule.h:138
BaseSelectionRule::fHasPatternAttribute
bool fHasPatternAttribute
Definition: BaseSelectionRule.h:78
BaseSelectionRule::GetAttributes
const AttributesMap_t & GetAttributes() const
Definition: BaseSelectionRule.cxx:150
BaseSelectionRule::kPattern
@ kPattern
Definition: BaseSelectionRule.h:50
BaseSelectionRule::fLineNumber
long fLineNumber
Definition: BaseSelectionRule.h:57
BaseSelectionRule::fAttributes
AttributesMap_t fAttributes
Definition: BaseSelectionRule.h:59
BaseSelectionRule::SetIndex
void SetIndex(long index)
Definition: BaseSelectionRule.h:99
BaseSelectionRule::fInterp
cling::Interpreter * fInterp
Definition: BaseSelectionRule.h:66
BaseSelectionRule::AttributesMap_t
std::unordered_map< std::string, std::string > AttributesMap_t
Definition: BaseSelectionRule.h:41
BaseSelectionRule::GetAttributeProtoName
const std::string & GetAttributeProtoName() const
Definition: BaseSelectionRule.h:113
BaseSelectionRule::fHasFromTypedefAttribute
bool fHasFromTypedefAttribute
Definition: BaseSelectionRule.h:82
BaseSelectionRule::fProtoPattern
std::string fProtoPattern
Definition: BaseSelectionRule.h:72
BaseSelectionRule::GetAttributeValue
bool GetAttributeValue(const std::string &attributeName, std::string &returnValue) const
Definition: BaseSelectionRule.cxx:116
BaseSelectionRule::kYes
@ kYes
Definition: BaseSelectionRule.h:44
BaseSelectionRule::fMatchFound
bool fMatchFound
Definition: BaseSelectionRule.h:63
BaseSelectionRule::fHasFilePatternAttribute
bool fHasFilePatternAttribute
Definition: BaseSelectionRule.h:81
BaseSelectionRule::fProtoName
std::string fProtoName
Definition: BaseSelectionRule.h:71
BaseSelectionRule::ESelect
ESelect
Definition: BaseSelectionRule.h:43
BaseSelectionRule::fIndex
long fIndex
Definition: BaseSelectionRule.h:56
BaseSelectionRule::fHasNameAttribute
bool fHasNameAttribute
Definition: BaseSelectionRule.h:76
operator<<
std::ostream & operator<<(std::ostream &out, const BaseSelectionRule &obj)
Definition: BaseSelectionRule.h:163
BaseSelectionRule::fSelFileName
std::string fSelFileName
Definition: BaseSelectionRule.h:58
BaseSelectionRule::HasAttributeWithName
bool HasAttributeWithName(const std::string &attributeName) const
Definition: BaseSelectionRule.cxx:108
BaseSelectionRule::SetAttributeValue
void SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
Definition: BaseSelectionRule.cxx:125
BaseSelectionRule::GetLineNumber
long GetLineNumber() const
Definition: BaseSelectionRule.h:101
BaseSelectionRule::SetMatchFound
void SetMatchFound(bool match)
Definition: BaseSelectionRule.cxx:518
BaseSelectionRule::fCXXRecordDecl
const clang::CXXRecordDecl * fCXXRecordDecl
Definition: BaseSelectionRule.h:64
clang
Definition: BaseSelectionRule.h:29
BaseSelectionRule::kDontCare
@ kDontCare
Definition: BaseSelectionRule.h:46
BaseSelectionRule::GetCXXRecordDecl
const clang::CXXRecordDecl * GetCXXRecordDecl() const
Definition: BaseSelectionRule.h:151
BaseSelectionRule::SetSelected
void SetSelected(ESelect sel)
Definition: BaseSelectionRule.cxx:98
BaseSelectionRule::GetAttributeName
const std::string & GetAttributeName() const
Definition: BaseSelectionRule.h:110
name
char name[80]
Definition: TGX11.cxx:110
BaseSelectionRule::fPattern
std::string fPattern
Definition: BaseSelectionRule.h:70
BaseSelectionRule::HasAttributeProtoPattern
bool HasAttributeProtoPattern() const
Definition: BaseSelectionRule.h:120
BaseSelectionRule::HasAttributeFileName
bool HasAttributeFileName() const
Definition: BaseSelectionRule.h:123
BaseSelectionRule::HasAttributeName
bool HasAttributeName() const
Definition: BaseSelectionRule.h:111
BaseSelectionRule::kNoMatch
@ kNoMatch
Definition: BaseSelectionRule.h:52
BaseSelectionRule::fHasProtoNameAttribute
bool fHasProtoNameAttribute
Definition: BaseSelectionRule.h:77
BaseSelectionRule::kName
@ kName
Definition: BaseSelectionRule.h:49
BaseSelectionRule::BaseSelectionRule
BaseSelectionRule(ESelect sel)
Definition: BaseSelectionRule.h:87
BaseSelectionRule::fHasFileNameAttribute
bool fHasFileNameAttribute
Definition: BaseSelectionRule.h:80
BaseSelectionRule
Definition: BaseSelectionRule.h:38
BaseSelectionRule::SetCXXRecordDecl
void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr)
Definition: BaseSelectionRule.cxx:533
BaseSelectionRule::Match
EMatchType Match(const clang::NamedDecl *decl, const std::string &name, const std::string &prototype, bool isLinkdef) const
Definition: BaseSelectionRule.cxx:185
ROOT::TMetaUtils::propNames::pattern
static const std::string pattern("pattern")
BaseSelectionRule::DebugPrint
virtual void DebugPrint() const
Definition: BaseSelectionRule.cxx:155
BaseSelectionRule::GetIndex
long GetIndex() const
Definition: BaseSelectionRule.h:98
BaseSelectionRule::fNArgsToKeep
std::string fNArgsToKeep
Definition: BaseSelectionRule.h:75