Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSelectorList.cxx
Go to the documentation of this file.
1// @(#)root/cont:$Id$
2// Author: Fons Rademakers 10/08/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
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/** \class TSelectorList
13\ingroup tree
14
15A TList derived class that makes sure that objects added to it
16are not linked to the currently open file (like histograms,
17eventlists and trees). Also it makes sure the name of the added
18object is unique. This class is used in the TSelector for the
19output list.
20*/
21
22#include "TSelectorList.h"
23#include "TMethodCall.h"
24
26
27////////////////////////////////////////////////////////////////////////////////
28/// If the class of obj has the SetDirectory(TDirectory*) method
29/// call it to unset the directory association. The objects in the
30/// selector list or owned by the list and not by the directory that
31/// was active when they were created. Returns true in case of success.
32
34{
35 if (!obj || !obj->IsA())
36 return kFALSE;
37
38 TMethodCall callEnv;
39 callEnv.InitWithPrototype(obj->IsA(), "SetDirectory", "TDirectory*");
40 if (!callEnv.IsValid())
41 return kFALSE;
42
43 callEnv.SetParam((Longptr_t) nullptr);
44 callEnv.Execute(obj);
45
46 return kTRUE;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Check for duplicate object names in the list. If an object with
51/// the same name is added then the merge function will fail that will
52/// look up objects in different output lists by name. Returns true
53/// in case name is unique.
54
56{
57 if (!obj)
58 return kFALSE;
59
60 TObject *org = FindObject(obj->GetName());
61 if (org == obj) {
62 Error("CheckDuplicateName","object with name: %s already in the list",obj->GetName());
63 return kFALSE;
64 }
65
66 if (org) {
67 Error("CheckDuplicateName","an object with the same name: %s is already in the list",obj->GetName());
68 return kFALSE;
69 }
70
71 return kTRUE;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Add at the start of the list
76
78{
79 UnsetDirectory(obj);
80 if (CheckDuplicateName(obj))
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Add at the start of the list
86
88{
89 UnsetDirectory(obj);
90 if (CheckDuplicateName(obj))
91 THashList::AddFirst(obj, opt);
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Add at the end of the list
96
98{
99 UnsetDirectory(obj);
100 if (CheckDuplicateName(obj))
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Add at the end of the list
106
108{
109 UnsetDirectory(obj);
110 if (CheckDuplicateName(obj))
111 THashList::AddLast(obj, opt);
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Add to the list.
116
118{
119 UnsetDirectory(obj);
120 if (CheckDuplicateName(obj))
121 THashList::AddAt(obj, idx);
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Add to the list.
126
128{
129 UnsetDirectory(obj);
130 if (CheckDuplicateName(obj))
131 THashList::AddAfter(after, obj);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Add to the list.
136
138{
139 UnsetDirectory(obj);
140 if (CheckDuplicateName(obj))
141 THashList::AddAfter(after, obj);
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Add to the list.
146
147void TSelectorList::AddBefore(const TObject *before, TObject *obj)
148{
149 UnsetDirectory(obj);
150 if (CheckDuplicateName(obj))
151 THashList::AddBefore(before, obj);
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Add to the list.
156
158{
159 UnsetDirectory(obj);
160 if (CheckDuplicateName(obj))
161 THashList::AddBefore(before, obj);
162}
long Longptr_t
Definition RtypesCore.h:82
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition THashList.cxx:69
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
TObject * FindObject(const char *name) const override
Find object using its name.
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition THashList.cxx:95
Method or function calling interface.
Definition TMethodCall.h:37
void Execute(const char *, const char *, int *=nullptr) override
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
void SetParam(Long_t l)
Add a long method parameter.
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual TClass * IsA() const
Definition TObject.h:243
A TList derived class that makes sure that objects added to it are not linked to the currently open f...
void AddBefore(const TObject *before, TObject *obj) override
Add to the list.
void AddFirst(TObject *obj) override
Add at the start of the list.
Bool_t UnsetDirectory(TObject *obj)
If the class of obj has the SetDirectory(TDirectory*) method call it to unset the directory associati...
void AddAt(TObject *obj, Int_t idx) override
Add to the list.
void AddLast(TObject *obj) override
Add at the end of the list.
void AddAfter(const TObject *after, TObject *obj) override
Add to the list.
Bool_t CheckDuplicateName(TObject *obj)
Check for duplicate object names in the list.
#define org(otri, vertexptr)
Definition triangle.c:1038