Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:30

0001 /*************************************************************************
0002  * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers.               *
0003  * All rights reserved.                                                  *
0004  *                                                                       *
0005  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0006  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0007  *************************************************************************/
0008 
0009 #ifndef ROOT7_Browsable_RElement
0010 #define ROOT7_Browsable_RElement
0011 
0012 #include <ROOT/Browsable/RHolder.hxx>
0013 
0014 #include <string>
0015 #include <vector>
0016 
0017 namespace ROOT {
0018 namespace Browsable {
0019 
0020 using RElementPath_t = std::vector<std::string>;
0021 
0022 class RLevelIter;
0023 
0024 class RItem;
0025 
0026 /** \class RElement
0027 \ingroup rbrowser
0028 \brief Basic element of browsable hierarchy. Provides access to data, creates iterator if any
0029 \author Sergey Linev <S.Linev@gsi.de>
0030 \date 2019-10-14
0031 \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0032 */
0033 
0034 class RElement {
0035 public:
0036 
0037    enum EContentKind {
0038       kNone,      ///< not recognized
0039       kText,      ///< "text" - plain text for code editor
0040       kImage,     ///< "image64" - base64 for supported image formats (png/gif/gpeg)
0041       kPng,       ///< "png" - plain png binary code, returned inside std::string
0042       kJpeg,      ///< "jpg" or "jpeg" - plain jpg binary code, returned inside std::string
0043       kJson,      ///< "json" representation of object, can be used in code editor
0044       kFileName   ///< "filename" - file name if applicable
0045    };
0046 
0047    static EContentKind GetContentKind(const std::string &kind);
0048 
0049    /** Possible actions on double-click */
0050    enum EActionKind {
0051       kActNone,    ///< do nothing
0052       kActBrowse,  ///< just browse (expand) item
0053       kActEdit,    ///< can provide data for text editor
0054       kActImage,   ///< can be shown in image viewer, can provide image
0055       kActDraw6,   ///< can be drawn inside ROOT6 canvas
0056       kActDraw7,   ///< can be drawn inside ROOT7 canvas
0057       kActCanvas,  ///< indicate that it is canvas and should be drawn directly
0058       kActTree,    ///< can be shown in tree viewer
0059       kActGeom     ///< can be shown in geometry viewer
0060    };
0061 
0062    virtual ~RElement() = default;
0063 
0064    /** Name of browsable, must be provided in derived classes */
0065    virtual std::string GetName() const = 0;
0066 
0067    /** Checks if element name match to provided value */
0068    virtual bool MatchName(const std::string &name) const { return name == GetName(); }
0069 
0070    /** Title of browsable (optional) */
0071    virtual std::string GetTitle() const { return ""; }
0072 
0073    /** Create iterator for childs elements if any */
0074    virtual std::unique_ptr<RLevelIter> GetChildsIter();
0075 
0076    /** Returns element content, depends from kind. Can be "text" or "image64" or "json" */
0077    virtual std::string GetContent(const std::string & = "text");
0078 
0079    /** Access object */
0080    virtual std::unique_ptr<RHolder> GetObject() { return nullptr; }
0081 
0082    /** Check if element contains provided pointer */
0083    virtual bool IsObject(void *) { return false; }
0084 
0085    /** Check if element can have childs */
0086    virtual bool IsFolder() const { return false; }
0087 
0088    virtual int GetNumChilds();
0089 
0090    /** Check if element still contains valid content */
0091    virtual bool CheckValid() { return true; }
0092 
0093    /** Get default action */
0094    virtual EActionKind GetDefaultAction() const { return kActNone; }
0095 
0096    /** Check if want to perform action */
0097    virtual bool IsCapable(EActionKind action) const { return action == GetDefaultAction(); }
0098 
0099    /** Should item representing element be expand by default */
0100    virtual bool IsExpandByDefault() const { return false; }
0101 
0102    /** Select element as active */
0103    virtual bool cd() { return false; }
0104 
0105    virtual std::unique_ptr<RItem> CreateItem() const;
0106 
0107    static std::shared_ptr<RElement> GetSubElement(std::shared_ptr<RElement> &elem, const RElementPath_t &path);
0108 
0109    static RElementPath_t ParsePath(const std::string &str);
0110 
0111    static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2);
0112 
0113    static std::string GetPathAsString(const RElementPath_t &path);
0114 
0115    static int ExtractItemIndex(std::string &name);
0116 };
0117 
0118 } // namespace Browsable
0119 } // namespace ROOT
0120 
0121 #endif