Logo ROOT   6.12/07
Reference Guide
TDisplayItem.hxx
Go to the documentation of this file.
1 /// \file ROOT/TDisplayItem.h
2 /// \ingroup Base ROOT7
3 /// \author Sergey Linev
4 /// \date 2017-05-31
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_TDisplayItem
17 #define ROOT7_TDisplayItem
18 
19 #include <string>
20 #include <memory>
21 #include <vector>
22 
23 namespace ROOT {
24 namespace Experimental {
25 class TCanvas;
26 
27 /** \class TDisplayItem
28  Base class for painting data for JS.
29  */
30 
31 class TDisplayItem {
32 protected:
33  std::string fObjectID;
34  std::string fOption;
35  int fKind;
36 
37 public:
38  TDisplayItem();
39  TDisplayItem(const TDisplayItem &rhs);
40  virtual ~TDisplayItem();
41 
42  void SetObjectIDAsPtr(void *ptr);
43  void SetObjectID(const char *id) { fObjectID = id; }
44  const char *GetObjectID() const { return fObjectID.c_str(); }
45 
46  void SetOption(const char *opt) { fOption = opt; }
47  const char *GetOption() { return fOption.c_str(); }
48 
49  void SetKind(int kind) { fKind = kind; }
50  int GetKind() const { return fKind; }
51 
52  static std::string MakeIDFromPtr(void *ptr);
53 };
54 
55 // list of snapshot for primitives in pad
56 
57 class TPadDisplayItem : public TDisplayItem {
58 protected:
59  std::vector<TDisplayItem *> fPrimitives;
60 
61 public:
62  TPadDisplayItem() : TDisplayItem(), fPrimitives() { SetKind(3); }
63  virtual ~TPadDisplayItem();
64  void Add(TDisplayItem *snap) { fPrimitives.push_back(snap); }
65  TDisplayItem *Last() const { return fPrimitives[fPrimitives.size() - 1]; }
66  void Clear();
67 };
68 
69 // direct pointer to some object without ownership
70 
71 template <class T>
73 protected:
74  const T *fSnapshot;
75 
76 public:
77  TOrdinaryDisplayItem(const T *addr) : TDisplayItem(), fSnapshot(addr) { SetKind(1); }
78  TOrdinaryDisplayItem(const TOrdinaryDisplayItem<T> &&rhs) : TDisplayItem(rhs), fSnapshot(rhs.fSnapshot) {}
79  virtual ~TOrdinaryDisplayItem() { fSnapshot = 0; }
80 
81  const T *GetSnapshot() const { return fSnapshot; }
82 };
83 
84 // unique pointer of specified class with ownership
85 
86 template <class T>
88 protected:
89  std::unique_ptr<T> fSnapshot;
90 
91 public:
92  TUniqueDisplayItem(T *addr) : TDisplayItem(), fSnapshot(addr) { SetKind(1); }
93  TUniqueDisplayItem(const TUniqueDisplayItem<T> &&rhs) : TDisplayItem(rhs), fSnapshot(std::move(rhs.fSnapshot)) {}
94  virtual ~TUniqueDisplayItem() {}
95 
96  T *GetSnapshot() const { return fSnapshot.get(); }
97 };
98 
99 } // namespace Experimental
100 } // namespace ROOT
101 
102 #endif
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
TUniqueDisplayItem(const TUniqueDisplayItem< T > &&rhs)
STL namespace.
std::vector< TDisplayItem * > fPrimitives
XFontStruct * id
Definition: TGX11.cxx:108
const char * GetObjectID() const
void SetObjectID(const char *id)
TOrdinaryDisplayItem(const TOrdinaryDisplayItem< T > &&rhs)
The Canvas class.
Definition: TCanvas.h:31
static std::string MakeIDFromPtr(void *ptr)
void SetOption(const char *opt)
void Add(TDisplayItem *snap)
Base class for painting data for JS.