 |
Changeset 3640
- Timestamp:
- 06/19/08 15:03:33
(3 months ago)
- Author:
- kris
- Message:
FileConduit? updates. FilePath? usage is being deprecated at this level
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2913 |
r3640 |
|
| 1 | 1 | module FileBucket; |
|---|
| 2 | 2 | |
|---|
| 3 | | private import tango.io.FilePath, |
|---|
| 4 | | tango.io.FileConduit; |
|---|
| | 3 | private import tango.io.FileConduit; |
|---|
| 5 | 4 | |
|---|
| 6 | 5 | private import tango.core.Exception; |
|---|
| … | … | |
| 56 | 55 | |
|---|
| 57 | 56 | // basic capacity for each record |
|---|
| 58 | | private FilePath path; |
|---|
| | 57 | private char[] path; |
|---|
| 59 | 58 | |
|---|
| 60 | 59 | // basic capacity for each record |
|---|
| … | … | |
| 87 | 86 | /********************************************************************** |
|---|
| 88 | 87 | |
|---|
| 89 | | Construct a FileBucket with the provided path and record- |
|---|
| 90 | | size. Selecting a record size that roughly matches the |
|---|
| 91 | | serialized content will limit 'thrashing'. |
|---|
| 92 | | |
|---|
| 93 | | **********************************************************************/ |
|---|
| 94 | | |
|---|
| 95 | | this (char[] path, BlockSize block) |
|---|
| 96 | | { |
|---|
| 97 | | this (new FilePath(path), block); |
|---|
| 98 | | } |
|---|
| 99 | | |
|---|
| 100 | | /********************************************************************** |
|---|
| 101 | | |
|---|
| 102 | 88 | Construct a FileBucket with the provided path, record-size, |
|---|
| 103 | 89 | and inital record count. The latter causes records to be |
|---|
| … | … | |
| 108 | 94 | **********************************************************************/ |
|---|
| 109 | 95 | |
|---|
| 110 | | this (FilePath path, BlockSize block, uint initialRecords = 100) |
|---|
| | 96 | this (char[] path, BlockSize block, uint initialRecords = 100) |
|---|
| 111 | 97 | { |
|---|
| 112 | 98 | this.path = path; |
|---|
| … | … | |
| 139 | 125 | **********************************************************************/ |
|---|
| 140 | 126 | |
|---|
| 141 | | FilePath getFilePath () |
|---|
| | 127 | char[] getFilePath () |
|---|
| 142 | 128 | { |
|---|
| 143 | 129 | return path; |
|---|
| … | … | |
| 250 | 236 | private static void eof (FileBucket bucket) |
|---|
| 251 | 237 | { |
|---|
| 252 | | throw new IOException ("Unexpected EOF in FileBucket '"~bucket.path.toString()~"'"); |
|---|
| | 238 | throw new IOException ("Unexpected EOF in FileBucket '"~bucket.path~"'"); |
|---|
| 253 | 239 | } |
|---|
| 254 | 240 | |
|---|
| r3547 |
r3640 |
|
| 61 | 61 | |
|---|
| 62 | 62 | auto props = new Properties!(char); |
|---|
| 63 | | props.load(new FilePath(args[1]), &configReader); |
|---|
| | 63 | props.load(args[1], &configReader); |
|---|
| 64 | 64 | |
|---|
| 65 | 65 | |
|---|
| r3625 |
r3640 |
|
| 37 | 37 | class File |
|---|
| 38 | 38 | { |
|---|
| 39 | | private PathView path_; |
|---|
| | 39 | private char[] path_; |
|---|
| 40 | 40 | |
|---|
| 41 | 41 | /*********************************************************************** |
|---|
| … | … | |
| 47 | 47 | this (char[] path) |
|---|
| 48 | 48 | { |
|---|
| 49 | | this (new FilePath (path)); |
|---|
| | 49 | path_ = path; |
|---|
| 50 | 50 | } |
|---|
| 51 | 51 | |
|---|
| … | … | |
| 56 | 56 | ***********************************************************************/ |
|---|
| 57 | 57 | |
|---|
| 58 | | this (PathView path) |
|---|
| | 58 | deprecated this (PathView path) |
|---|
| 59 | 59 | { |
|---|
| 60 | | path_ = path; |
|---|
| | 60 | this(path.toString); |
|---|
| 61 | 61 | } |
|---|
| 62 | 62 | |
|---|
| … | … | |
| 80 | 80 | ***********************************************************************/ |
|---|
| 81 | 81 | |
|---|
| 82 | | final PathView path () |
|---|
| | 82 | deprecated final PathView path () |
|---|
| 83 | 83 | { |
|---|
| 84 | | return path_; |
|---|
| | 84 | return new FilePath(path_); |
|---|
| 85 | 85 | } |
|---|
| 86 | 86 | |
|---|
| r2765 |
r3640 |
|
| 13 | 13 | module tango.io.UnicodeFile; |
|---|
| 14 | 14 | |
|---|
| 15 | | public import tango.io.FilePath; |
|---|
| | 15 | private import tango.io.FilePath; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | private import tango.io.FileConduit; |
|---|
| … | … | |
| 102 | 102 | { |
|---|
| 103 | 103 | private UnicodeBom!(T) bom; |
|---|
| 104 | | private PathView path_; |
|---|
| | 104 | private char[] path_; |
|---|
| 105 | 105 | |
|---|
| 106 | 106 | /*********************************************************************** |
|---|
| … | … | |
| 112 | 112 | ***********************************************************************/ |
|---|
| 113 | 113 | |
|---|
| 114 | | this (PathView path, Encoding encoding) |
|---|
| | 114 | this (char[] path, Encoding encoding) |
|---|
| 115 | 115 | { |
|---|
| 116 | 116 | bom = new UnicodeBom!(T)(encoding); |
|---|
| … | … | |
| 126 | 126 | ***********************************************************************/ |
|---|
| 127 | 127 | |
|---|
| 128 | | this (char[] path, Encoding encoding) |
|---|
| 129 | | { |
|---|
| 130 | | this (new FilePath(path), encoding); |
|---|
| | 128 | this (FilePath path, Encoding encoding) |
|---|
| | 129 | { |
|---|
| | 130 | this (path.toString, encoding); |
|---|
| 131 | 131 | } |
|---|
| 132 | 132 | |
|---|
| … | … | |
| 150 | 150 | ***********************************************************************/ |
|---|
| 151 | 151 | |
|---|
| 152 | | PathView path () |
|---|
| | 152 | deprecated PathView path () |
|---|
| | 153 | { |
|---|
| | 154 | return new FilePath (path_); |
|---|
| | 155 | } |
|---|
| | 156 | |
|---|
| | 157 | /*********************************************************************** |
|---|
| | 158 | |
|---|
| | 159 | Return the associated file path |
|---|
| | 160 | |
|---|
| | 161 | ***********************************************************************/ |
|---|
| | 162 | |
|---|
| | 163 | char[] toString () |
|---|
| 153 | 164 | { |
|---|
| 154 | 165 | return path_; |
|---|
| r3485 |
r3640 |
|
| 89 | 89 | } |
|---|
| 90 | 90 | |
|---|
| 91 | | auto length = conduit.path.fileSize; |
|---|
| | 91 | auto length = conduit.length; |
|---|
| 92 | 92 | if (length is 0) |
|---|
| 93 | 93 | { |
|---|
| r3547 |
r3640 |
|
| 39 | 39 | ***********************************************************************/ |
|---|
| 40 | 40 | |
|---|
| 41 | | static void load (FilePath path, void delegate (T[] name, T[] value) dg) |
|---|
| | 41 | deprecated static void load (FilePath path, void delegate (T[] name, T[] value) dg) |
|---|
| | 42 | { |
|---|
| | 43 | load (path.toString, dg); |
|---|
| | 44 | } |
|---|
| | 45 | |
|---|
| | 46 | /*********************************************************************** |
|---|
| | 47 | |
|---|
| | 48 | Load properties from the named file, and pass each of them |
|---|
| | 49 | to the provided delegate. |
|---|
| | 50 | |
|---|
| | 51 | ***********************************************************************/ |
|---|
| | 52 | |
|---|
| | 53 | static void load (char[] path, void delegate (T[] name, T[] value) dg) |
|---|
| 42 | 54 | { |
|---|
| 43 | 55 | auto fc = new FileConduit (path); |
|---|
| … | … | |
| 92 | 104 | ***********************************************************************/ |
|---|
| 93 | 105 | |
|---|
| 94 | | static void save (FilePath path, T[][T[]] properties) |
|---|
| | 106 | deprecated static void save (FilePath path, T[][T[]] properties) |
|---|
| | 107 | { |
|---|
| | 108 | save (path.toString, properties); |
|---|
| | 109 | } |
|---|
| | 110 | |
|---|
| | 111 | /*********************************************************************** |
|---|
| | 112 | |
|---|
| | 113 | Write properties to the provided filepath |
|---|
| | 114 | |
|---|
| | 115 | ***********************************************************************/ |
|---|
| | 116 | |
|---|
| | 117 | static void save (char[] path, T[][T[]] properties) |
|---|
| 95 | 118 | { |
|---|
| 96 | 119 | auto fc = new FileConduit (path, FileConduit.WriteCreate); |
|---|
| r3547 |
r3640 |
|
| 40 | 40 | ***********************************************************************/ |
|---|
| 41 | 41 | |
|---|
| 42 | | this (FilePath fp, Appender.Layout how = null) |
|---|
| | 42 | this (char[] fp, Appender.Layout how = null) |
|---|
| 43 | 43 | { |
|---|
| 44 | 44 | // Get a unique fingerprint for this instance |
|---|
| 45 | | mask_ = register (fp.toString); |
|---|
| | 45 | mask_ = register (fp); |
|---|
| 46 | 46 | |
|---|
| 47 | 47 | // make it shareable for read |
|---|
| … | … | |
| 59 | 59 | ***********************************************************************/ |
|---|
| 60 | 60 | |
|---|
| 61 | | this (char[] fp, Appender.Layout how = null) |
|---|
| | 61 | deprecated this (FilePath fp, Appender.Layout how = null) |
|---|
| 62 | 62 | { |
|---|
| 63 | | this (new FilePath(fp), how); |
|---|
| | 63 | this (fp.toString, how); |
|---|
| 64 | 64 | } |
|---|
| 65 | 65 | |
|---|
| r3547 |
r3640 |
|
| 15 | 15 | private import tango.time.Time; |
|---|
| 16 | 16 | |
|---|
| 17 | | private import tango.io.FilePath, |
|---|
| | 17 | private import Path = tango.io.Path, |
|---|
| 18 | 18 | tango.io.FileConduit; |
|---|
| 19 | 19 | |
|---|
| … | … | |
| 33 | 33 | { |
|---|
| 34 | 34 | private Mask mask_; |
|---|
| 35 | | private FilePath[] paths; |
|---|
| | 35 | private char[][] paths; |
|---|
| 36 | 36 | private int index; |
|---|
| 37 | 37 | private IBuffer buffer; |
|---|
| … | … | |
| 63 | 63 | { |
|---|
| 64 | 64 | x[0] = '0' + i; |
|---|
| 65 | | |
|---|
| 66 | | auto p = new FilePath (path); |
|---|
| 67 | | p.name = p.name ~ x; |
|---|
| | 65 | auto c = Path.parse (path); |
|---|
| | 66 | auto p = c.toString[0..$-c.suffix.length] ~ x ~ c.suffix; |
|---|
| 68 | 67 | paths ~= p; |
|---|
| 69 | 68 | |
|---|
| 70 | 69 | // use the most recent file in the set |
|---|
| 71 | | if (p.exists) |
|---|
| | 70 | if (Path.exists(p)) |
|---|
| 72 | 71 | { |
|---|
| 73 | | auto modified = p.modified; |
|---|
| | 72 | auto modified = Path.modified(p); |
|---|
| 74 | 73 | if (modified > mostRecent) |
|---|
| 75 | 74 | { |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic