1 | /* |
2 | data.h - wraps a gpgme data object |
3 | Copyright (C) 2003,2004 Klarälvdalens Datakonsult AB |
4 | |
5 | This file is part of GPGME++. |
6 | |
7 | GPGME++ is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. |
11 | |
12 | GPGME++ is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU Library General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Library General Public License |
18 | along with GPGME++; see the file COPYING.LIB. If not, write to the |
19 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #ifndef __GPGMEPP_DATA_H__ |
24 | #define __GPGMEPP_DATA_H__ |
25 | |
26 | #include <gpgme++/global.h> |
27 | |
28 | #include <boost/shared_ptr.hpp> |
29 | |
30 | #include <sys/types.h> // for size_t, off_t |
31 | #include <cstdio> // FILE |
32 | #include <algorithm> |
33 | |
34 | namespace GpgME { |
35 | |
36 | class DataProvider; |
37 | class Error; |
38 | |
39 | class GPGMEPP_EXPORT Data { |
40 | struct Null {}; |
41 | public: |
42 | /* implicit */ Data( const Null & ); |
43 | Data(); |
44 | explicit Data( gpgme_data_t data ); |
45 | |
46 | // Memory-Based Data Buffers: |
47 | Data( const char * buffer, size_t size, bool copy=true ); |
48 | explicit Data( const char * filename ); |
49 | Data( const char * filename, off_t offset, size_t length ); |
50 | Data( std::FILE * fp, off_t offset, size_t length ); |
51 | // File-Based Data Buffers: |
52 | explicit Data( std::FILE * fp ); |
53 | explicit Data( int fd ); |
54 | // Callback-Based Data Buffers: |
55 | explicit Data( DataProvider * provider ); |
56 | |
57 | static Null null; |
58 | |
59 | const Data & operator=( Data other ) { |
60 | swap( other ); |
61 | return *this; |
62 | } |
63 | |
64 | void swap( Data & other ) { |
65 | using std::swap; |
66 | swap( this->d, other.d ); |
67 | } |
68 | |
69 | bool isNull() const; |
70 | |
71 | enum Encoding { |
72 | AutoEncoding, |
73 | BinaryEncoding, |
74 | Base64Encoding, |
75 | ArmorEncoding |
76 | }; |
77 | Encoding encoding() const; |
78 | Error setEncoding( Encoding encoding ); |
79 | |
80 | char * fileName() const; |
81 | Error setFileName( const char * name ); |
82 | |
83 | ssize_t read( void * buffer, size_t length ); |
84 | ssize_t write( const void * buffer, size_t length ); |
85 | off_t seek( off_t offset, int whence ); |
86 | |
87 | class Private; |
88 | Private * impl() { return d.get(); } |
89 | const Private * impl() const { return d.get(); } |
90 | private: |
91 | boost::shared_ptr<Private> d; |
92 | }; |
93 | |
94 | } |
95 | |
96 | GPGMEPP_MAKE_STD_SWAP_SPECIALIZATION( Data ) |
97 | |
98 | #endif // __GPGMEPP_DATA_H__ |
99 | |