~ubuntu-branches/ubuntu/vivid/dune-grid/vivid

« back to all changes in this revision

Viewing changes to dune/grid/io/file/vtk/b64enc.hh

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2014-02-14 10:49:16 UTC
  • mfrom: (1.3.1) (5.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20140214104916-2clchnny3eu7ks4w
Tags: 2.3.0-2
InstallĀ /usr/share/dune-grid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 
// vi: set et ts=8 sw=4 sts=4:
 
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
2
// vi: set et ts=4 sw=2 sts=2:
3
3
 
4
4
#ifndef DUNE_GRID_IO_FILE_VTK_B64ENC_HH
5
5
#define DUNE_GRID_IO_FILE_VTK_B64ENC_HH
8
8
 
9
9
namespace Dune {
10
10
 
11
 
/** @file
12
 
    @author Christian Engwer
13
 
    @brief Simple base64 encode
14
 
 
15
 
    @{
16
 
*/
17
 
 
18
 
/** @brief endoing table */
19
 
const char base64table[] =
20
 
{
 
11
  /** @file
 
12
      @author Christian Engwer
 
13
      @brief Simple base64 encode
 
14
 
 
15
      @{
 
16
   */
 
17
 
 
18
  /** @brief endoing table */
 
19
  const char base64table[] =
 
20
  {
21
21
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
22
22
    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
23
23
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
24
24
    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
25
25
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
26
 
};
 
26
  };
27
27
 
28
 
/** @brief struct with three bytes of text */
29
 
struct b64txt
30
 
{
 
28
  /** @brief struct with three bytes of text */
 
29
  struct b64txt
 
30
  {
31
31
    typedef unsigned char size_type;
32
32
    size_type size;
33
33
    char txt[3];
34
34
    int read(const char* t, size_type s)
35
35
    {
36
 
        size = s>=3?3:s;
37
 
        txt[2] = s>0?t[0]:0;
38
 
        txt[1] = s>1?t[1]:0;
39
 
        txt[0] = s>2?t[2]:0;
40
 
        return size;
 
36
      size = s>=3 ? 3 : s;
 
37
      txt[2] = s>0 ? t[0] : 0;
 
38
      txt[1] = s>1 ? t[1] : 0;
 
39
      txt[0] = s>2 ? t[2] : 0;
 
40
      return size;
41
41
    }
42
42
    void put(const char c)
43
43
    {
44
 
        assert (size < 3);
45
 
        txt[2-size++] = c;
 
44
      assert (size < 3);
 
45
      txt[2-size++] = c;
46
46
    }
47
 
};
 
47
  };
48
48
 
49
 
/** struct with four six bit chunks */
50
 
struct b64data
51
 
{
 
49
  /** struct with four six bit chunks */
 
50
  struct b64data
 
51
  {
52
52
    typedef unsigned char size_type;
53
53
    size_type size;
54
54
    unsigned A : 6;
57
57
    unsigned D : 6;
58
58
    void write(char* t)
59
59
    {
60
 
        t[3] = size>2?base64table[A]:'=';
61
 
        t[2] = size>1?base64table[B]:'=';
62
 
        t[1] = size>0?base64table[C]:'=';
63
 
        t[0] = size>0?base64table[D]:'=';
64
 
        size = 0;
 
60
      t[3] = size>2 ? base64table[A] : '=';
 
61
      t[2] = size>1 ? base64table[B] : '=';
 
62
      t[1] = size>0 ? base64table[C] : '=';
 
63
      t[0] = size>0 ? base64table[D] : '=';
 
64
      size = 0;
65
65
    }
66
 
};
 
66
  };
67
67
 
68
 
/** @brief union representing the three byte text aswell as the four 6 bit chunks */
69
 
union b64chunk
70
 
{
 
68
  /** @brief union representing the three byte text aswell as the four 6 bit chunks */
 
69
  union b64chunk
 
70
  {
71
71
    b64txt txt;
72
 
    b64data data; 
73
 
};
 
72
    b64data data;
 
73
  };
74
74
 
75
 
/** @} */
 
75
  /** @} */
76
76
 
77
77
} // namespace Dune
78
78