Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSystemDirectory.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Christian Bormann 13/10/97
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 TSystemDirectory
13\ingroup Base
14
15Describes an Operating System directory for the browser.
16*/
17
18#include "TSystemDirectory.h"
19#include "TSystem.h"
20#include "TBrowser.h"
21#include "TOrdCollection.h"
22#include "TList.h"
23
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Create a system directory object.
28
32
33////////////////////////////////////////////////////////////////////////////////
34/// Create a system directory object.
35
36TSystemDirectory::TSystemDirectory(const char *dirname, const char *path) :
37 TSystemFile(dirname, path)
38{
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Delete system directory object.
43
49
50////////////////////////////////////////////////////////////////////////////////
51/// Returns a TList of TSystemFile objects representing the contents
52/// of the directory. It's the responsibility of the user to delete
53/// the list (the list owns the contained objects).
54/// Returns 0 in case of errors.
55
57{
58 void *dir = gSystem->OpenDirectory(GetTitle());
59 if (!dir) return nullptr;
60
61 const char *file = nullptr;
62 TList *contents = new TList;
63 contents->SetOwner();
64 while ((file = gSystem->GetDirEntry(dir))) {
65 if (IsItDirectory(file)) {
67 if (file[0] == '.' && file[1] == '\0')
69 else if (file[0] == '.' && file[1] == '.' && file[2] == '.')
71 else {
73 if (!sdirpath.EndsWith("/"))
74 sdirpath += "/";
75 sdirpath += file;
76 }
77 contents->Add(new TSystemDirectory(file, sdirpath.Data()));
78 } else
79 contents->Add(new TSystemFile(file, GetTitle()));
80 }
82 return contents;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Create a system directory object.
87
89{
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Check if name is a directory.
96
98{
100 Long_t id, flags, modtime;
101 const char *dirfile = GetTitle();
103
105 flags = id = size = modtime = 0;
106 gSystem->GetPathInfo(name, &id, &size, &flags, &modtime);
107 Int_t isdir = (Int_t)flags & 2;
108
110 return isdir ? kTRUE : kFALSE;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Browse OS system directories.
115
117{
118 // Collections to keep track of all browser objects that have been
119 // generated. It's main goal is to prevent the continuous
120 // allocations of new objects with the same names during browsing.
123
124 const char *name = GetTitle();
127 const char *file;
128
130
131 if (GetName()[0] == '.' && GetName()[1] == '.')
133
134 void *dir = gSystem->OpenDirectory(name);
135
136 if (!dir)
137 return;
138
139 while ((file = gSystem->GetDirEntry(dir))) {
140 if (b->TestBit(TBrowser::kNoHidden) && file[0] == '.' && file[1] != '.' )
141 continue;
142 if (IsItDirectory(file)) {
144 if (!strcmp(file, "."))
145 sdirpath = name;
146 else if (!strcmp(file, ".."))
148 else {
149 sdirpath = name;
150 if (!sdirpath.EndsWith("/"))
151 sdirpath += "/";
152 sdirpath += file;
153 }
154 if (!(sdir = FindDirObj(sdirpath.Data()))) {
155 sdir = new TSystemDirectory(file, sdirpath.Data());
157 }
158 b->Add(sdir, file);
159 } else {
160 if (!(sfile = FindFileObj(file, gSystem->WorkingDirectory()))) {
163 }
164 b->Add(sfile, file);
165 }
166 }
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Method that returns system directory object if it
172/// exists in list, 0 otherwise.
173
175{
177 for (int i = 0; i < size; i++) {
179 if (!strcmp(name, obj->GetTitle()))
180 return obj;
181 }
182 return nullptr;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Method that returns system file object if it exists in
187/// list, 0 otherwise.
188
189TSystemFile *TSystemDirectory::FindFileObj(const char *name, const char *dir)
190{
192 for (int i = 0; i < size; i++) {
194 if (!strcmp(name, obj->GetName()) && !strcmp(dir, obj->GetTitle()))
195 return obj;
196 }
197 return nullptr;
198}
#define b(i)
Definition RSha256.hxx:100
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char name[80]
Definition TGX11.cxx:110
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
@ kNoHidden
Definition TBrowser.h:55
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
Ordered collection.
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
void Add(TObject *obj) override
Basic string class.
Definition TString.h:138
Describes an Operating System directory for the browser.
virtual TList * GetListOfFiles() const
Returns a TList of TSystemFile objects representing the contents of the directory.
virtual void SetDirectory(const char *name)
Create a system directory object.
virtual ~TSystemDirectory()
Delete system directory object.
TSystemFile * FindFileObj(const char *name, const char *dir)
Method that returns system file object if it exists in list, 0 otherwise.
TSystemDirectory()
Create a system directory object.
Bool_t IsItDirectory(const char *name) const
Check if name is a directory.
TOrdCollection * fFilesInBrowser
void SetName(const char *name) override
Set the name of the TNamed.
TSystemDirectory * FindDirObj(const char *name)
Method that returns system directory object if it exists in list, 0 otherwise.
void Browse(TBrowser *b) override
Browse OS system directories.
void SetTitle(const char *title) override
Set the title of the TNamed.
TOrdCollection * fDirsInBrowser
A TSystemFile describes an operating system file.
Definition TSystemFile.h:29
TSystemFile()
TSystemFile default constructor.
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:855
virtual void * OpenDirectory(const char *name)
Open a directory.
Definition TSystem.cxx:846
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition TSystem.cxx:1409
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:863
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition TSystem.cxx:872
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:944
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:881
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1042