OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConvertBase64.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 /* This file is derived from the libb64 project which itself was released to public domain.
15  * For details, see http://sourceforge.net/projects/libb64. Original code by Chris Venter
16  * c++ wrapper for a base64 encoding and decoding algorithm
17 */
18 
19 #ifndef OSGDB_CONVERTBASE64_H
20 #define OSGDB_CONVERTBASE64_H 1
21 
22 #include <iostream>
23 #include <string>
24 #include <vector>
25 
26 #include <osgDB/Export>
27 
28 namespace osgDB
29 {
30  const int BUFFERSIZE = 8192;
31 
32  typedef enum
33  {
36 
37  typedef enum
38  {
41 
42  typedef struct
43  {
45  char result;
46  int stepcount;
48 
49  typedef struct
50  {
52  char plainchar;
54 
56  {
57  public:
58  Base64encoder(int buffersize_in = BUFFERSIZE)
59  : _buffersize(buffersize_in)
60  {}
61 
62  int encode(char value_in);
63 
64  int encode(const char* code_in, const int length_in, char* plaintext_out);
65 
66  int encode_end(char* plaintext_out);
67 
68  void encode(std::istream& istream_in, std::ostream& ostream_in);
69 
70  void encode(const char* chars_in, int length_in, std::string& code_out);
71 
72  private:
73  base64_encodestate _state;
74  int _buffersize;
75  };
76 
78  {
79  public:
80  Base64decoder(int buffersize_in = BUFFERSIZE)
81  : _buffersize(buffersize_in)
82  {}
83 
84  int decode(char value_in);
85 
86  int decode(const char* code_in, const int length_in, char* plaintext_out);
87 
88  void decode(std::istream& istream_in, std::ostream& ostream_in);
89 
90  // Decode strings, returns one char* of appropriate size
91  // Note that deallocation of char* is up to the caller of this method
92  char* decode(const std::vector<std::string>& str_in, std::vector<unsigned int>& pos_out);
93 
94  private:
95  base64_decodestate _state;
96  int _buffersize;
97  };
98 
99 } // namespace osgDB
100 
101 #endif // BASE64_DECODE_H
102 
Base64decoder(int buffersize_in=BUFFERSIZE)
Definition: ConvertBase64.h:80
const int BUFFERSIZE
Definition: ConvertBase64.h:30
base64_decodestep step
Definition: ConvertBase64.h:51
base64_decodestep
Definition: ConvertBase64.h:32
Definition: Archive.h:24
#define OSGDB_EXPORT
Definition: Export.h:39
Base64encoder(int buffersize_in=BUFFERSIZE)
Definition: ConvertBase64.h:58
base64_encodestep
Definition: ConvertBase64.h:37
base64_encodestep step
Definition: ConvertBase64.h:44