1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
* Defines the interface to the CachedDirectory class.
28
#ifndef MYSYS_CACHED_DIRECTORY_H
29
#define MYSYS_CACHED_DIRECTORY_H
39
* A utility class to handle processing the entries/files within a directory.
41
* This class will allow the user to either get a list of the entry names
42
* within a given directory, or, alternatively, apply a function to each
43
* entry as it is read from the directory.
52
Entry(std::string in_name)
56
typedef std::vector<Entry *> Entries;
58
int error; ///< Error code stored from various syscalls
59
Entries entries; ///< Entries in the directory
62
* Encapsulate the logic to open the directory.
63
* @param[in] dirPath The path to the directory to open and read.
64
* @retval true Success
65
* @retval false Failure
67
bool open(const std::string &dirPath);
70
explicit CachedDirectory()
75
* Constructor taking full directory path as sole parameter.
77
* @param[in] Path to the directory to open
79
CachedDirectory(const std::string &in_path);
81
* Destructor. Cleans up any resources we've taken
86
* Returns whether the CachedDirectory object is in a failed state
88
inline bool fail() const
94
* Returns the stored error code of the last action the directory
95
* object took (open, read, etc)
97
inline int getError() const
103
* Return a list of directory entries populated in the call to open().
106
* You must call the open() method before getList() if you want the
107
* list contain any elements.
110
* A vector of strings containing the directory entry names.
112
inline const Entries &getEntries()
118
#endif /* MYSYS_CACHED_DIRECTORY_H */