Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataTarget.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Cinder.h"
26 #include "cinder/Url.h"
27 #include "cinder/Stream.h"
28 
29 #include <string>
30 
31 namespace cinder {
32 
33 typedef std::shared_ptr<class DataTarget> DataTargetRef;
34 
35 class DataTarget {
36  public:
37  virtual bool providesFilePath() = 0;
38  virtual bool providesUrl() = 0;
39 
40  const fs::path& getFilePath() const;
41  const Url& getUrl() const;
42  const fs::path& getFilePathHint() const;
43 
44  virtual OStreamRef getStream() = 0;
45 
46  protected:
47  DataTarget( const fs::path &aFilePath, const Url &aUrl )
48  : mFilePath( aFilePath ), mUrl( aUrl )
49  {}
50  virtual ~DataTarget() {}
51 
52  void setFilePathHint( const fs::path &aFilePathHint );
53 
55  fs::path mFilePath;
56  fs::path mFilePathHint;
58 };
59 
60 
61 typedef std::shared_ptr<class DataTargetPath> DataTargetPathRef;
62 
63 class DataTargetPath : public DataTarget {
64  public:
65  static DataTargetPathRef createRef( const fs::path &path );
66 
67  virtual bool providesFilePath() { return true; }
68  virtual bool providesUrl() { return false; }
69 
70  virtual OStreamRef getStream();
71 
72  protected:
73  explicit DataTargetPath( const fs::path &path );
74 
76 };
77 
78 
79 typedef std::shared_ptr<class DataTargetStream> DataTargetStreamRef;
80 
81 class DataTargetStream : public DataTarget {
82  public:
83  static DataTargetStreamRef createRef( OStreamRef stream );
84 
85  virtual bool providesFilePath() { return false; }
86  virtual bool providesUrl() { return false; }
87 
88  virtual OStreamRef getStream() { return mStream; }
89 
90  protected:
91  DataTargetStream( OStreamRef stream );
92 
94 };
95 
97 DataTargetPathRef writeFile( const fs::path &path, bool createParents = true );
98 
99 } // namespace cinder
virtual OStreamRef getStream()
Definition: DataTarget.cpp:63
Definition: DataTarget.h:81
std::shared_ptr< class DataTargetPath > DataTargetPathRef
Definition: DataTarget.h:61
void setFilePathHint(const fs::path &aFilePathHint)
Definition: DataTarget.cpp:30
virtual bool providesUrl()=0
static DataTargetPathRef createRef(const fs::path &path)
Definition: DataTarget.cpp:52
fs::path mFilePathHint
Definition: DataTarget.h:56
std::shared_ptr< class OStream > OStreamRef
Definition: Stream.h:107
const fs::path & getFilePath() const
Definition: DataTarget.cpp:35
virtual bool providesUrl()
Definition: DataTarget.h:68
virtual ~DataTarget()
Definition: DataTarget.h:50
Buffer mBuffer
Definition: DataTarget.h:54
Definition: Buffer.h:31
const Url & getUrl() const
Definition: DataTarget.cpp:40
std::shared_ptr< class DataTargetStream > DataTargetStreamRef
Definition: DataTarget.h:79
virtual OStreamRef getStream()=0
DataTargetStream(OStreamRef stream)
Definition: DataTarget.cpp:78
Definition: DataTarget.h:35
DataTarget(const fs::path &aFilePath, const Url &aUrl)
Definition: DataTarget.h:47
const fs::path & getFilePathHint() const
Definition: DataTarget.cpp:45
virtual OStreamRef getStream()
Definition: DataTarget.h:88
virtual bool providesFilePath()
Definition: DataTarget.h:85
fs::path mFilePath
Definition: DataTarget.h:55
Url mUrl
Definition: DataTarget.h:57
OStreamRef mStream
Definition: DataTarget.h:93
Definition: DataTarget.h:63
OStreamFileRef mStream
Definition: DataTarget.h:75
DataTargetPathRef writeFile(const fs::path &path, bool createParents=true)
Returns a DataTarget to file path path, and optionally creates any necessary directories when createP...
Definition: DataTarget.cpp:86
std::shared_ptr< class DataTarget > DataTargetRef
Definition: DataTarget.h:33
std::shared_ptr< class OStreamFile > OStreamFileRef
Definition: Stream.h:189
static DataTargetStreamRef createRef(OStreamRef stream)
Definition: DataTarget.cpp:73
virtual bool providesFilePath()
Definition: DataTarget.h:67
virtual bool providesUrl()
Definition: DataTarget.h:86
DataTargetPath(const fs::path &path)
Definition: DataTarget.cpp:57
virtual bool providesFilePath()=0
Definition: Url.h:31