Logo ROOT  
Reference Guide
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
26
27////////////////////////////////////////////////////////////////////////////////
28/// Create a system directory object.
29
31{
32}
33
34////////////////////////////////////////////////////////////////////////////////
35/// Create a system directory object.
36
37TSystemDirectory::TSystemDirectory(const char *dirname, const char *path) :
38 TSystemFile(dirname, path)
39{
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Delete system directory object.
44
46{
47 delete fDirsInBrowser;
48 delete fFilesInBrowser;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Returns a TList of TSystemFile objects representing the contents
53/// of the directory. It's the responsibility of the user to delete
54/// the list (the list owns the contained objects).
55/// Returns 0 in case of errors.
56
58{
59 void *dir = gSystem->OpenDirectory(GetTitle());
60 if (!dir) return nullptr;
61
62 const char *file = nullptr;
63 TList *contents = new TList;
64 contents->SetOwner();
65 while ((file = gSystem->GetDirEntry(dir))) {
66 if (IsItDirectory(file)) {
67 TString sdirpath;
68 if (file[0] == '.' && file[1] == '\0')
69 sdirpath = GetTitle();
70 else if (file[0] == '.' && file[1] == '.' && file[2] == '.')
71 sdirpath = gSystem->GetDirName(GetTitle());
72 else {
73 sdirpath = GetTitle();
74 if (!sdirpath.EndsWith("/"))
75 sdirpath += "/";
76 sdirpath += file;
77 }
78 contents->Add(new TSystemDirectory(file, sdirpath.Data()));
79 } else
80 contents->Add(new TSystemFile(file, GetTitle()));
81 }
83 return contents;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Create a system directory object.
88
90{
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Check if name is a directory.
97
99{
101 Long_t id, flags, modtime;
102 const char *dirfile = GetTitle();
103 TString savDir = gSystem->WorkingDirectory();
104
105 gSystem->ChangeDirectory(dirfile);
106 flags = id = size = modtime = 0;
107 gSystem->GetPathInfo(name, &id, &size, &flags, &modtime);
108 Int_t isdir = (Int_t)flags & 2;
109
110 gSystem->ChangeDirectory(savDir);
111 return isdir ? kTRUE : kFALSE;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Browse OS system directories.
116
118{
119 // Collections to keep track of all browser objects that have been
120 // generated. It's main goal is to prevent the continuous
121 // allocations of new objects with the same names during browsing.
124
125 const char *name = GetTitle();
126 TSystemFile *sfile;
127 TSystemDirectory *sdir;
128 const char *file;
129
131
132 if (GetName()[0] == '.' && GetName()[1] == '.')
134
135 void *dir = gSystem->OpenDirectory(name);
136
137 if (!dir)
138 return;
139
140 while ((file = gSystem->GetDirEntry(dir))) {
141 if (b->TestBit(TBrowser::kNoHidden) && file[0] == '.' && file[1] != '.' )
142 continue;
143 if (IsItDirectory(file)) {
144 TString sdirpath;
145 if (!strcmp(file, "."))
146 sdirpath = name;
147 else if (!strcmp(file, ".."))
148 sdirpath = gSystem->GetDirName(name);
149 else {
150 sdirpath = name;
151 if (!sdirpath.EndsWith("/"))
152 sdirpath += "/";
153 sdirpath += file;
154 }
155 if (!(sdir = FindDirObj(sdirpath.Data()))) {
156 sdir = new TSystemDirectory(file, sdirpath.Data());
157 fDirsInBrowser->Add(sdir);
158 }
159 b->Add(sdir, file);
160 } else {
161 if (!(sfile = FindFileObj(file, gSystem->WorkingDirectory()))) {
162 sfile = new TSystemFile(file, gSystem->WorkingDirectory());
163 fFilesInBrowser->Add(sfile);
164 }
165 b->Add(sfile, file);
166 }
167 }
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Method that returns system directory object if it
173/// exists in list, 0 otherwise.
174
176{
178 for (int i = 0; i < size; i++) {
180 if (!strcmp(name, obj->GetTitle()))
181 return obj;
182 }
183 return nullptr;
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Method that returns system file object if it exists in
188/// list, 0 otherwise.
189
190TSystemFile *TSystemDirectory::FindFileObj(const char *name, const char *dir)
191{
193 for (int i = 0; i < size; i++) {
195 if (!strcmp(name, obj->GetName()) && !strcmp(dir, obj->GetTitle()))
196 return obj;
197 }
198 return nullptr;
199}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
long Long_t
Definition: RtypesCore.h:54
long long Long64_t
Definition: RtypesCore.h:80
const Bool_t kTRUE
Definition: RtypesCore.h:100
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
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:560
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.
Definition: TCollection.h:184
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:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
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:136
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2223
const char * Data() const
Definition: TString.h:369
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.
Definition: TSystemFile.cxx:30
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:848
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:839
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:1401
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:856
virtual Bool_t ChangeDirectory(const char *path)
Change directory.
Definition: TSystem.cxx:865
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:937
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:874
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1035
Definition: file.py:1