Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/filesys/directory.h @ 9719

Last change on this file since 9719 was 9719, checked in by bensch, 18 years ago

directory expansion

File size: 4.2 KB
Line 
1/*!
2 * @file directory.h
3 * @brief Definition of the Directory Handler class
4 */
5
6
7/**
8 * Copyright (C) 2002 Bart Vanhauwaert
9 *
10 * Permission to use, copy, modify, distribute and sell this software
11 * for any purpose is hereby granted without fee. This license
12 * includes (but is not limited to) standalone compilation or as part
13 * of a larger project.
14 *
15 * This software is provided "as is" without express or implied warranty.
16 *
17 * For a full statement on warranty and terms and conditions for
18 * copying, distribution and modification, please see the comment block
19 * at the end of this file.
20 *
21 * Version 1
22 *
23 */
24
25#ifndef __DIRECTORY_H_
26#define __DIRECTORY_H_
27
28#include "file.h"
29#include <vector>
30
31//! A Directory is a Special file, that contains multiple Files.
32/**
33 * @example Correct usage
34 * Directory dir("/var/log");
35 * dir.open();
36 * if (dir.fileNameInDir("emerge.log"))
37 *  { // do stuff; }
38 */
39class Directory : public File
40{
41public:
42  Directory(const std::string& directoryName = "");
43  Directory(const Directory& directory);
44  virtual ~Directory();
45
46  virtual bool open();
47  virtual bool close();
48
49  bool create();
50
51  Directory operator+(const Directory& dir) const;
52  Directory& operator+=(const Directory& dir);
53  Directory& operator--();
54  Directory& operator--(int);
55  Directory parentDir() const;
56
57
58  /** @returns if the Directory was opened */
59  bool isOpen() const { return this->_opened; }
60  /** @returns the FileCount (count of files contained in this directory) */
61  unsigned int fileCount() const { return _fileNames.size(); };
62  /** @returns the FileNames contained inside of the Directory */
63  const std::vector<std::string>& fileNames() const { return this->_fileNames; };
64  /** @returns the i'th FileName @param fileNumber the fileNumber (must not bigger than fileCount()) */
65  const std::string& operator[](unsigned int fileNumber) const { return this->_fileNames[fileNumber]; };
66  /** @returns a formated string containing the FileName, prepended with the directory-Name */
67  std::string fileNameInDir(unsigned int fileNumber) const { return this->name() + "/" + _fileNames[fileNumber]; };
68  /** @returns a File pointing to the File @param fileNumber the fileNumber (must not bigger than fileCount()) */
69  File getFile(unsigned int fileNumber) const { return File(fileNameInDir(fileNumber)); };
70
71public:
72  static const char           delimiter;        //!< A Delimiter (*nix: '/', windows: '\\')
73
74private:
75  bool                        _opened;          //!< If the directory was opened.
76  std::vector<std::string>    _fileNames;       //!< The List of Files contained in the directory. (will be filled when open was called.)
77};
78
79#endif /* __DIRECTORY_H_ */
80
81/**
82 *
83 * The "library", above, refers to the collection of software functions
84 * and/or data contained in this file, prepared so as to be conveniently
85 * compiled and linked with application programs (which use some of those
86 * functions and data) to form executables.
87 *
88 *                             NO WARRANTY
89 *
90 * 1. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
91 * WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
92 * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
93 * OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
94 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
95 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
96 * PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
97 * LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
98 * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
99 *
100 * 2. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
101 * WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
102 * AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
103 * FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
104 * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
105 * LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
106 * RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
107 * FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
108 * SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
109 * DAMAGES.
110 *
111 * END OF TERMS AND CONDITIONS
112 *
113 */
114
Note: See TracBrowser for help on using the repository browser.