Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:19

0001 /*************************************************************************
0002  * Copyright (C) 1995-2019, 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_RItem
0010 #define ROOT7_Browsable_RItem
0011 
0012 #include <string>
0013 #include "RtypesCore.h"
0014 
0015 namespace ROOT {
0016 namespace Browsable {
0017 
0018 /** \class RItem
0019 \ingroup rbrowser
0020 \brief Representation of single item in the browser
0021 */
0022 
0023 class RItem {
0024 protected:
0025    std::string name;     ///< item name
0026    int nchilds{0};       ///< number of childs
0027    std::string icon;     ///< icon associated with item
0028    std::string title;    ///< item title
0029    std::string fsize;    ///< item size
0030    std::string mtime;    ///< modification time
0031    bool checked{false};  ///< is checked, not yet used
0032    bool expanded{false}; ///< is expanded
0033 public:
0034 
0035    RItem() = default;
0036    RItem(const std::string &_name, int _nchilds = 0, const std::string &_icon = "") : name(_name), nchilds(_nchilds), icon(_icon) {}
0037    // must be here, one needs virtual table for correct streaming of sub-classes
0038    virtual ~RItem() = default;
0039 
0040    const std::string &GetName() const { return name; }
0041    const std::string &GetIcon() const { return icon; }
0042    const std::string &GetTitle() const { return title; }
0043    const std::string &GetSize() const { return fsize; }
0044    const std::string &GetMTime() const { return mtime; }
0045 
0046    virtual bool IsFolder() const { return nchilds != 0; }
0047    virtual bool IsHidden() const { return false; }
0048 
0049    void SetChecked(bool on = true) { checked = on; }
0050    void SetExpanded(bool on = true) { expanded = on; }
0051 
0052    void SetName(const std::string &_name) { name = _name; }
0053    void SetTitle(const std::string &_title) { title = _title; }
0054    void SetIcon(const std::string &_icon) { icon = _icon; }
0055    void SetSize(const std::string &_size) { fsize = _size; }
0056    void SetMTime(const std::string &_mtime) { mtime = _mtime; }
0057 
0058    void SetSize(Long64_t _size)
0059    {
0060       if (_size > 4096) {
0061          Long64_t _ksize = _size / 1024;
0062          if (_ksize > 1024) {
0063             // 3.7MB is more informative than just 3MB
0064             fsize = std::to_string(_ksize/1024) + "." + std::to_string((_ksize%1024)/103) + "M";
0065          } else {
0066             fsize = std::to_string(_ksize) + "." + std::to_string((_size%1024)/103) + "K";
0067          }
0068       } else {
0069          fsize = std::to_string(_size);
0070       }
0071    }
0072 
0073    virtual bool Compare(const RItem *b, const std::string &) const
0074    {
0075       if (IsFolder() != b->IsFolder())
0076          return IsFolder();
0077       return GetName() < b->GetName();
0078    }
0079 };
0080 
0081 } // namespace Browsable
0082 } // namespace ROOT
0083 
0084 #endif
0085 
0086