Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNameReg.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooNameReg.cxx
19\class RooNameReg
20\ingroup Roofitcore
21
22RooNameReg is a registry for `const char*` names. For each unique
23name (which is not necessarily a unique pointer in the C++ standard),
24a unique pointer to a TNamed object is returned that can be used for
25fast searches and comparisons.
26**/
27
28#include "RooNameReg.h"
29
30#include <iostream>
31#include <memory>
32using namespace std ;
33
34
36 TNamed("RooNameReg","RooFit Name Registry")
37{}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Destructor
41
43{
44}
45
46
47////////////////////////////////////////////////////////////////////////////////
48/// Return reference to singleton instance
49
51{
52 static RooNameReg instance;
53 return instance;
54}
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Return a unique TNamed pointer for given C++ string
59
60const TNamed* RooNameReg::constPtr(const char* inStr)
61{
62 // Handle null pointer case explicitly
63 if (inStr==0) return 0 ;
64
65 // See if name is already registered ;
66 auto elm = _map.find(inStr) ;
67 if (elm != _map.end()) return elm->second.get();
68
69 // If not, register now
70 auto t = make_unique<TNamed>(inStr,inStr);
71 auto ret = t.get();
72 _map.emplace(std::string(inStr), std::move(t));
73
74 return ret;
75}
76
77
78////////////////////////////////////////////////////////////////////////////////
79/// Return a unique TNamed pointer for given C++ string
80
81const TNamed* RooNameReg::ptr(const char* stringPtr)
82{
83 if (stringPtr==0) return 0 ;
84 return instance().constPtr(stringPtr) ;
85}
86
87
88////////////////////////////////////////////////////////////////////////////////
89/// If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name).
90
91const TNamed* RooNameReg::known(const char* inStr)
92{
93 // Handle null pointer case explicitly
94 if (inStr==0) return 0 ;
96 const auto elm = reg._map.find(inStr);
97 return elm != reg._map.end() ? elm->second.get() : nullptr;
98}
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// The renaming counter has to be incremented every time a RooAbsArg is
103/// renamed. This is a protected function, and only the friend class RooAbsArg
104/// should call it when it gets renamed.
105
108}
109
110
111////////////////////////////////////////////////////////////////////////////////
112// Return a reference to a counter that keeps track how often a RooAbsArg was
113/// renamed in this RooFit process.
114
115const std::size_t& RooNameReg::renameCounter() {
116 return instance()._renameCounter;
117}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void reg
RooNameReg is a registry for const char* names.
Definition RooNameReg.h:25
std::unordered_map< std::string, std::unique_ptr< TNamed > > _map
Definition RooNameReg.h:56
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
std::size_t _renameCounter
Definition RooNameReg.h:57
const TNamed * constPtr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
static RooNameReg & instance()
Return reference to singleton instance.
~RooNameReg() override
Destructor.
static const TNamed * known(const char *stringPtr)
If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name)...
static void incrementRenameCounter()
The renaming counter has to be incremented every time a RooAbsArg is renamed.
static const std::size_t & renameCounter()
renamed in this RooFit process.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29