Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/filesys/directory.h @ 10298

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 4.3 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() + Directory::delimiter + _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
79File operator+(const Directory& dir, const File& file);
80
81#endif /* __DIRECTORY_H_ */
82
83/**
84 *
85 * The "library", above, refers to the collection of software functions
86 * and/or data contained in this file, prepared so as to be conveniently
87 * compiled and linked with application programs (which use some of those
88 * functions and data) to form executables.
89 *
90 *                             NO WARRANTY
91 *
92 * 1. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
93 * WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
94 * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
95 * OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
96 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
97 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
98 * PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
99 * LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
100 * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
101 *
102 * 2. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
103 * WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
104 * AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
105 * FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
106 * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
107 * LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
108 * RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
109 * FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
110 * SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
111 * DAMAGES.
112 *
113 * END OF TERMS AND CONDITIONS
114 *
115 */
116
Note: See TracBrowser for help on using the repository browser.