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 <map>
26#include <unordered_map>
27#include <list>
28#include <iosfwd>
29
30namespace clang {
31 class NamedDecl;
32 class CXXRecordDecl;
33 class Type;
34}
35namespace cling {
36 class Interpreter;
37}
38
40{
41public:
42 typedef std::unordered_map<std::string, std::string> AttributesMap_t; // The liste of selection rule's attributes (name, pattern, ...)
43
44 enum ESelect { // a rule could be selected, vetoed or we don't care about it
48 };
54 };
55
56private:
57 long fIndex; // Index indicating the ordering of the rules.
58 long fLineNumber=-1; // Line number of the selection file where the rule is located
59 std::string fSelFileName=""; // Name of the selection file
60 AttributesMap_t fAttributes; // list of the attributes of the selection/exclusion rule
61 ESelect fIsSelected; // selected/vetoed/don't care
62 std::list<std::string> fSubPatterns; // a list of subpatterns, generated form a pattern/proto_pattern attribute
63 std::list<std::string> fFileSubPatterns; // a list of subpatterns, generated form a file_pattern attribute
64 bool fMatchFound; // this is true if this selection rule has been used at least once
65 const clang::CXXRecordDecl *fCXXRecordDecl; // Record decl of the entity searched for.
66 const clang::Type *fRequestedType; // Same as the record decl but with some of the typedef preserved (Double32_t, Float16_t, etc..)
67 cling::Interpreter *fInterp;
68
69 // Cached for performance
70 std::string fName = "";
71 std::string fPattern = "";
72 std::string fProtoName = "";
73 std::string fProtoPattern = "";
74 std::string fFileName = "";
75 std::string fFilePattern = "";
76 std::string fNArgsToKeep = "";
77 bool fHasNameAttribute = false;
84 bool fIsFromTypedef = false;
85
86public:
87
89
90 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) {}
91
92 BaseSelectionRule(long index, ESelect sel, const std::string& attributeName, const std::string& attributeValue, cling::Interpreter &interp, const char* selFileName = "",long lineno=-1);
93
94 virtual ~BaseSelectionRule() = default;
95
96 virtual void DebugPrint() const;
97 virtual void Print(std::ostream &out) const = 0;
98
99 long GetIndex() const { return fIndex; }
100 void SetIndex(long index) { fIndex=index; }
101
102 long GetLineNumber() const { return fLineNumber; }
103 const char* GetSelFileName() const { return fSelFileName.c_str(); }
104
105 bool HasAttributeWithName(const std::string& attributeName) const; // returns true if there is an attribute with the specified name
106
107 void FillCache(); // Fill the cache for performant attribute retrival
108
109 bool GetAttributeValue(const std::string& attributeName, std::string& returnValue) const; // returns the value of the attribute with name attributeName
110
111 inline const std::string& GetAttributeName() const {return fName;};
112 inline bool HasAttributeName() const {return fHasNameAttribute;};
113
114 inline const std::string& GetAttributeProtoName() const {return fProtoName;};
115 inline bool HasAttributeProtoName() const {return fHasProtoNameAttribute;};
116
117 inline const std::string& GetAttributePattern() const {return fPattern;};
118 inline bool HasAttributePattern() const {return fHasPatternAttribute;};
119
120 inline const std::string& GetAttributeProtoPattern() const {return fProtoPattern;};
122
123 inline const std::string& GetAttributeFileName() const {return fFileName;};
124 inline bool HasAttributeFileName() const {return fHasFileNameAttribute;};
125
126 inline const std::string& GetAttributeFilePattern() const {return fFilePattern;};
128
129 inline bool IsFromTypedef() const {return fIsFromTypedef;};
131
132 inline const std::string& GetAttributeNArgsToKeep() const {return fNArgsToKeep;};
133
134 void SetAttributeValue(const std::string& attributeName, const std::string& attributeValue); // sets an attribute with name attribute name and value attributeValue
135
136 ESelect GetSelected() const;
137 void SetSelected(ESelect sel);
138
139 bool HasInterpreter() const {return fInterp!=NULL; };
140 void SetInterpreter(cling::Interpreter& interp) {fInterp=&interp; };
141
142 const AttributesMap_t& GetAttributes() const; // returns the list of attributes
143 void PrintAttributes(int level) const; // prints the list of attributes - level is the number of tabs from the beginning of the line
144 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
145
146 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
147
148 void SetMatchFound(bool match); // set fMatchFound
149 bool GetMatchFound() const; // get fMatchFound
150
151 const clang::Type *GetRequestedType() const;
152 inline const clang::CXXRecordDecl *GetCXXRecordDecl() const {return fCXXRecordDecl;} ;
153 void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr);
154
155protected:
156
157 // Checks if the test string matches against the pattern (which has produced the list of sub-patterns patterns_list). There is
158 // difference if we are processing linkdef.h or selection.xmlpatterns
159 inline bool CheckPattern(const std::string& test, const std::string& pattern, const std::list<std::string>& patterns_list, bool isLinkdef) const;
160
161 inline void ProcessPattern(const std::string& pattern, std::list<std::string>& out) const; // divides a pattern into a list of sub-patterns
162};
163
164inline std::ostream &operator<<(std::ostream& out, const BaseSelectionRule &obj)
165{
166 obj.Print(out);
167 return out;
168}
169#endif
std::ostream & operator<<(std::ostream &out, const BaseSelectionRule &obj)
char name[80]
Definition: TGX11.cxx:109
std::string fFilePattern
void SetAttributeValue(const std::string &attributeName, const std::string &attributeValue)
bool HasAttributeFileName() const
BaseSelectionRule(long index, cling::Interpreter &interp, const char *selFileName="", long lineno=-1)
bool HasAttributePattern() const
long GetIndex() const
const std::string & GetAttributePattern() const
bool HasAttributeFilePattern() const
bool GetAttributeValue(const std::string &attributeName, std::string &returnValue) const
virtual ~BaseSelectionRule()=default
bool CheckPattern(const std::string &test, const std::string &pattern, const std::list< std::string > &patterns_list, bool isLinkdef) const
bool HasInterpreter() const
void SetSelected(ESelect sel)
void ProcessPattern(const std::string &pattern, std::list< std::string > &out) const
const std::string & GetAttributeFileName() const
const clang::CXXRecordDecl * fCXXRecordDecl
std::string fProtoName
const std::string & GetAttributeNArgsToKeep() const
std::list< std::string > fSubPatterns
bool HasAttributeProtoPattern() const
const clang::CXXRecordDecl * GetCXXRecordDecl() const
virtual void DebugPrint() const
EMatchType Match(const clang::NamedDecl *decl, const std::string &name, const std::string &prototype, bool isLinkdef) const
void SetCXXRecordDecl(const clang::CXXRecordDecl *decl, const clang::Type *typeptr)
void SetIndex(long index)
void SetInterpreter(cling::Interpreter &interp)
const std::string & GetAttributeName() const
bool GetMatchFound() const
const clang::Type * GetRequestedType() const
long GetLineNumber() const
std::string fProtoPattern
const AttributesMap_t & GetAttributes() const
const std::string & GetAttributeProtoName() const
const std::string & GetAttributeProtoPattern() const
ESelect GetSelected() const
bool HasAttributeWithName(const std::string &attributeName) const
bool HasAttributeName() const
AttributesMap_t fAttributes
bool HasAttributeFromTypedef() const
std::string fNArgsToKeep
cling::Interpreter * fInterp
bool IsFromTypedef() const
const clang::Type * fRequestedType
void SetMatchFound(bool match)
std::unordered_map< std::string, std::string > AttributesMap_t
void PrintAttributes(int level) const
std::string fSelFileName
std::list< std::string > fFileSubPatterns
bool HasAttributeProtoName() const
BaseSelectionRule(ESelect sel)
const char * GetSelFileName() const
virtual void Print(std::ostream &out) const =0
const std::string & GetAttributeFilePattern() const
Type
enumeration specifying the integration types.
Definition: test.py:1