ATLAS Offline Software
DiskList.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
18 #include <SampleHandler/DiskList.h>
19 
20 #include <RootCoreUtils/Assert.h>
21 #include <RootCoreUtils/ThrowMsg.h>
22 
23 //
24 // method implementations
25 //
26 
27 namespace SH
28 {
30  testInvariant () const
31  {
33  }
34 
35 
37  ~DiskList ()
38  {
39  RCU_DESTROY_INVARIANT (this);
40  }
41 
42 
43 
45  DiskList ()
46  : m_state (S_BLANK)
47  {
48  RCU_NEW_INVARIANT (this);
49  }
50 
51 
52 
54  next ()
55  {
56  RCU_CHANGE_INVARIANT (this);
57  switch (m_state)
58  {
59  case S_BLANK:
60  case S_VALID:
61  m_state = S_BROKEN;
62  if (getNext())
63  m_state = S_VALID;
64  else
65  m_state = S_DONE;
66  return m_state == S_VALID;
67  case S_DONE:
68  RCU_THROW_MSG ("already finished processing list");
69  case S_BROKEN:
70  RCU_THROW_MSG ("list is in error state");
71  };
72  return false; // compiler dummy
73  }
74 
75 
76 
77  std::string DiskList ::
78  path () const
79  {
80  RCU_READ_INVARIANT (this);
81  RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
82  return getPath();
83  }
84 
85 
86 
87  std::string DiskList ::
88  fileName () const
89  {
90  // no invariant used
91  std::string result = path();
92  std::string::size_type split = result.rfind ('/');
93  if (split != std::string::npos)
94  result = result.substr (split + 1);
95  return result;
96  }
97 
98 
99 
101  openDir () const
102  {
103  RCU_READ_INVARIANT (this);
104  RCU_REQUIRE2_SOFT (m_state == S_VALID, "getNext() has not been called successfully");
105  return doOpenDir();
106  }
107 
108 
109 
110  std::string DiskList ::
111  dirname () const
112  {
113  RCU_READ_INVARIANT (this);
114  return getDirname ();
115  }
116 }
SH::DiskList::~DiskList
virtual ~DiskList()
standard destructor
Definition: DiskList.cxx:37
SH::DiskList::DiskList
DiskList()
standard constructor
Definition: DiskList.cxx:45
get_generator_info.result
result
Definition: get_generator_info.py:21
SH::DiskList::doOpenDir
virtual DiskList * doOpenDir() const =0
make a new list object for the sub-directory
SH::DiskList::getDirname
virtual std::string getDirname() const =0
the base path for the directory listed
SH::DiskList::fileName
std::string fileName() const
the filename for the current entry
Definition: DiskList.cxx:88
SH::DiskList::getNext
virtual bool getNext()=0
get the next list entry
SH::DiskList::testInvariant
void testInvariant() const
test the invariant of this object
Definition: DiskList.cxx:30
Assert.h
SH::DiskList::S_VALID
@ S_VALID
holding a valid entry
Definition: DiskList.h:169
SH::DiskList
an interface for listing directory contents, locally or on a file server
Definition: DiskList.h:32
DiskList.h
SH::DiskList::m_state
State m_state
the current state
Definition: DiskList.h:174
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
SH::DiskList::next
bool next()
get the next list entry
Definition: DiskList.cxx:54
ThrowMsg.h
RCU_REQUIRE2_SOFT
#define RCU_REQUIRE2_SOFT(x, y)
Definition: Assert.h:155
SH::DiskList::openDir
DiskList * openDir() const
make a new list object for the sub-directory
Definition: DiskList.cxx:101
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
SH::DiskList::getPath
virtual std::string getPath() const =0
the path for the current entry.
SH::DiskList::S_BLANK
@ S_BLANK
just initialized
Definition: DiskList.h:168
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
SH::DiskList::path
std::string path() const
the path for the current entry.
Definition: DiskList.cxx:78
SH::DiskList::S_BROKEN
@ S_BROKEN
an error occured
Definition: DiskList.h:171
SH::DiskList::dirname
std::string dirname() const
the base path for the directory listed
Definition: DiskList.cxx:111
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
SH::DiskList::S_DONE
@ S_DONE
finished reading entries
Definition: DiskList.h:170
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233