Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
platform/DirHandle.h@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 166:3a9487d57a5c | 1 | /* mbed Microcontroller Library |
thedo | 166:3a9487d57a5c | 2 | * Copyright (c) 2006-2013 ARM Limited |
thedo | 166:3a9487d57a5c | 3 | * |
thedo | 166:3a9487d57a5c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 166:3a9487d57a5c | 5 | * you may not use this file except in compliance with the License. |
thedo | 166:3a9487d57a5c | 6 | * You may obtain a copy of the License at |
thedo | 166:3a9487d57a5c | 7 | * |
thedo | 166:3a9487d57a5c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 166:3a9487d57a5c | 9 | * |
thedo | 166:3a9487d57a5c | 10 | * Unless required by applicable law or agreed to in writing, software |
thedo | 166:3a9487d57a5c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 166:3a9487d57a5c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 166:3a9487d57a5c | 13 | * See the License for the specific language governing permissions and |
thedo | 166:3a9487d57a5c | 14 | * limitations under the License. |
thedo | 166:3a9487d57a5c | 15 | */ |
thedo | 166:3a9487d57a5c | 16 | #ifndef MBED_DIRHANDLE_H |
thedo | 166:3a9487d57a5c | 17 | #define MBED_DIRHANDLE_H |
thedo | 166:3a9487d57a5c | 18 | |
thedo | 166:3a9487d57a5c | 19 | #include <stdint.h> |
thedo | 166:3a9487d57a5c | 20 | #include "platform/platform.h" |
thedo | 166:3a9487d57a5c | 21 | #include "platform/FileHandle.h" |
thedo | 166:3a9487d57a5c | 22 | |
thedo | 166:3a9487d57a5c | 23 | namespace mbed { |
thedo | 166:3a9487d57a5c | 24 | /** \addtogroup platform */ |
thedo | 166:3a9487d57a5c | 25 | |
thedo | 166:3a9487d57a5c | 26 | |
thedo | 166:3a9487d57a5c | 27 | /** Represents a directory stream. Objects of this type are returned |
thedo | 166:3a9487d57a5c | 28 | * by an opendir function. The core functions are read and seek, |
thedo | 166:3a9487d57a5c | 29 | * but only a subset needs to be provided. |
thedo | 166:3a9487d57a5c | 30 | * |
thedo | 166:3a9487d57a5c | 31 | * If a FileSystemLike class defines the opendir method, then the |
thedo | 166:3a9487d57a5c | 32 | * directories of an object of that type can be accessed by |
thedo | 166:3a9487d57a5c | 33 | * DIR *d = opendir("/example/directory") (or opendir("/example") |
thedo | 166:3a9487d57a5c | 34 | * to open the root of the filesystem), and then using readdir(d) etc. |
thedo | 166:3a9487d57a5c | 35 | * |
thedo | 166:3a9487d57a5c | 36 | * The root directory is considered to contain all FileHandle and |
thedo | 166:3a9487d57a5c | 37 | * FileSystem objects, so the DIR* returned by opendir("/") will |
thedo | 166:3a9487d57a5c | 38 | * reflect this. |
thedo | 166:3a9487d57a5c | 39 | * |
thedo | 166:3a9487d57a5c | 40 | * @note to create a directory, @see Dir |
thedo | 166:3a9487d57a5c | 41 | * @note Synchronization level: Set by subclass |
thedo | 166:3a9487d57a5c | 42 | * @ingroup platform |
thedo | 166:3a9487d57a5c | 43 | */ |
thedo | 166:3a9487d57a5c | 44 | class DirHandle { |
thedo | 166:3a9487d57a5c | 45 | public: |
thedo | 166:3a9487d57a5c | 46 | virtual ~DirHandle() {} |
thedo | 166:3a9487d57a5c | 47 | |
thedo | 166:3a9487d57a5c | 48 | /** Read the next directory entry |
thedo | 166:3a9487d57a5c | 49 | * |
thedo | 166:3a9487d57a5c | 50 | * @param ent The directory entry to fill out |
thedo | 166:3a9487d57a5c | 51 | * @return 1 on reading a filename, 0 at end of directory, negative error on failure |
thedo | 166:3a9487d57a5c | 52 | */ |
thedo | 166:3a9487d57a5c | 53 | virtual ssize_t read(struct dirent *ent) = 0; |
thedo | 166:3a9487d57a5c | 54 | |
thedo | 166:3a9487d57a5c | 55 | /** Close a directory |
thedo | 166:3a9487d57a5c | 56 | * |
thedo | 166:3a9487d57a5c | 57 | * return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 58 | */ |
thedo | 166:3a9487d57a5c | 59 | virtual int close() = 0; |
thedo | 166:3a9487d57a5c | 60 | |
thedo | 166:3a9487d57a5c | 61 | /** Set the current position of the directory |
thedo | 166:3a9487d57a5c | 62 | * |
thedo | 166:3a9487d57a5c | 63 | * @param offset Offset of the location to seek to, |
thedo | 166:3a9487d57a5c | 64 | * must be a value returned from tell |
thedo | 166:3a9487d57a5c | 65 | */ |
thedo | 166:3a9487d57a5c | 66 | virtual void seek(off_t offset) = 0; |
thedo | 166:3a9487d57a5c | 67 | |
thedo | 166:3a9487d57a5c | 68 | /** Get the current position of the directory |
thedo | 166:3a9487d57a5c | 69 | * |
thedo | 166:3a9487d57a5c | 70 | * @return Position of the directory that can be passed to rewind |
thedo | 166:3a9487d57a5c | 71 | */ |
thedo | 166:3a9487d57a5c | 72 | virtual off_t tell() = 0; |
thedo | 166:3a9487d57a5c | 73 | |
thedo | 166:3a9487d57a5c | 74 | /** Rewind the current position to the beginning of the directory |
thedo | 166:3a9487d57a5c | 75 | */ |
thedo | 166:3a9487d57a5c | 76 | virtual void rewind() = 0; |
thedo | 166:3a9487d57a5c | 77 | |
thedo | 166:3a9487d57a5c | 78 | /** Get the sizeof the directory |
thedo | 166:3a9487d57a5c | 79 | * |
thedo | 166:3a9487d57a5c | 80 | * @return Number of files in the directory |
thedo | 166:3a9487d57a5c | 81 | */ |
thedo | 166:3a9487d57a5c | 82 | virtual size_t size() |
thedo | 166:3a9487d57a5c | 83 | { |
thedo | 166:3a9487d57a5c | 84 | off_t off = tell(); |
thedo | 166:3a9487d57a5c | 85 | size_t size = 0; |
thedo | 166:3a9487d57a5c | 86 | struct dirent *ent = new struct dirent; |
thedo | 166:3a9487d57a5c | 87 | |
thedo | 166:3a9487d57a5c | 88 | rewind(); |
thedo | 166:3a9487d57a5c | 89 | while (read(ent) > 0) { |
thedo | 166:3a9487d57a5c | 90 | size += 1; |
thedo | 166:3a9487d57a5c | 91 | } |
thedo | 166:3a9487d57a5c | 92 | seek(off); |
thedo | 166:3a9487d57a5c | 93 | |
thedo | 166:3a9487d57a5c | 94 | delete ent; |
thedo | 166:3a9487d57a5c | 95 | return size; |
thedo | 166:3a9487d57a5c | 96 | } |
thedo | 166:3a9487d57a5c | 97 | |
thedo | 166:3a9487d57a5c | 98 | /** Closes the directory. |
thedo | 166:3a9487d57a5c | 99 | * |
thedo | 166:3a9487d57a5c | 100 | * @returns |
thedo | 166:3a9487d57a5c | 101 | * 0 on success, |
thedo | 166:3a9487d57a5c | 102 | * -1 on error. |
thedo | 166:3a9487d57a5c | 103 | */ |
thedo | 166:3a9487d57a5c | 104 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::close") |
thedo | 166:3a9487d57a5c | 105 | virtual int closedir() { return close(); }; |
thedo | 166:3a9487d57a5c | 106 | |
thedo | 166:3a9487d57a5c | 107 | /** Return the directory entry at the current position, and |
thedo | 166:3a9487d57a5c | 108 | * advances the position to the next entry. |
thedo | 166:3a9487d57a5c | 109 | * |
thedo | 166:3a9487d57a5c | 110 | * @returns |
thedo | 166:3a9487d57a5c | 111 | * A pointer to a dirent structure representing the |
thedo | 166:3a9487d57a5c | 112 | * directory entry at the current position, or NULL on reaching |
thedo | 166:3a9487d57a5c | 113 | * end of directory or error. |
thedo | 166:3a9487d57a5c | 114 | */ |
thedo | 166:3a9487d57a5c | 115 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::read") |
thedo | 166:3a9487d57a5c | 116 | virtual struct dirent *readdir() |
thedo | 166:3a9487d57a5c | 117 | { |
thedo | 166:3a9487d57a5c | 118 | static struct dirent ent; |
thedo | 166:3a9487d57a5c | 119 | return (read(&ent) > 0) ? &ent : NULL; |
thedo | 166:3a9487d57a5c | 120 | } |
thedo | 166:3a9487d57a5c | 121 | |
thedo | 166:3a9487d57a5c | 122 | /** Resets the position to the beginning of the directory. |
thedo | 166:3a9487d57a5c | 123 | */ |
thedo | 166:3a9487d57a5c | 124 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::rewind") |
thedo | 166:3a9487d57a5c | 125 | virtual void rewinddir() { rewind(); } |
thedo | 166:3a9487d57a5c | 126 | |
thedo | 166:3a9487d57a5c | 127 | /** Returns the current position of the DirHandle. |
thedo | 166:3a9487d57a5c | 128 | * |
thedo | 166:3a9487d57a5c | 129 | * @returns |
thedo | 166:3a9487d57a5c | 130 | * the current position, |
thedo | 166:3a9487d57a5c | 131 | * -1 on error. |
thedo | 166:3a9487d57a5c | 132 | */ |
thedo | 166:3a9487d57a5c | 133 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::tell") |
thedo | 166:3a9487d57a5c | 134 | virtual off_t telldir() { return tell(); } |
thedo | 166:3a9487d57a5c | 135 | |
thedo | 166:3a9487d57a5c | 136 | /** Sets the position of the DirHandle. |
thedo | 166:3a9487d57a5c | 137 | * |
thedo | 166:3a9487d57a5c | 138 | * @param location The location to seek to. Must be a value returned by telldir. |
thedo | 166:3a9487d57a5c | 139 | */ |
thedo | 166:3a9487d57a5c | 140 | MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by DirHandle::seek") |
thedo | 166:3a9487d57a5c | 141 | virtual void seekdir(off_t location) { seek(location); } |
thedo | 166:3a9487d57a5c | 142 | }; |
thedo | 166:3a9487d57a5c | 143 | |
thedo | 166:3a9487d57a5c | 144 | |
thedo | 166:3a9487d57a5c | 145 | } // namespace mbed |
thedo | 166:3a9487d57a5c | 146 | |
thedo | 166:3a9487d57a5c | 147 | #endif /* MBED_DIRHANDLE_H */ |
thedo | 166:3a9487d57a5c | 148 |