~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/transparent_file.cc

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2003 MySQL AB
2
 
 
3
 
  This program is free software; you can redistribute it and/or modify
4
 
  it under the terms of the GNU General Public License as published by
5
 
  the Free Software Foundation; version 2 of the License.
6
 
 
7
 
  This program is distributed in the hope that it will be useful,
8
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
  GNU General Public License for more details.
11
 
 
12
 
  You should have received a copy of the GNU General Public License
13
 
  along with this program; if not, write to the Free Software
14
 
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
 
17
 
#include "config.h"
18
 
#include <cstdlib>
19
 
#include "drizzled/internal/my_sys.h"
20
 
#include "transparent_file.h"
21
 
 
22
 
using namespace drizzled;
23
 
 
24
 
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
25
 
{
26
 
  buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
27
 
}
28
 
 
29
 
Transparent_file::~Transparent_file()
30
 
{
31
 
  free(buff);
32
 
}
33
 
 
34
 
void Transparent_file::init_buff(int filedes_arg)
35
 
{
36
 
  filedes= filedes_arg;
37
 
  /* read the beginning of the file */
38
 
  lower_bound= 0;
39
 
  lseek(filedes, 0, SEEK_SET);
40
 
  if (filedes && buff)
41
 
    upper_bound= internal::my_read(filedes, buff, buff_size, MYF(0));
42
 
}
43
 
 
44
 
unsigned char *Transparent_file::ptr()
45
 
{
46
 
  return buff;
47
 
}
48
 
 
49
 
off_t Transparent_file::start()
50
 
{
51
 
  return lower_bound;
52
 
}
53
 
 
54
 
off_t Transparent_file::end()
55
 
{
56
 
  return upper_bound;
57
 
}
58
 
 
59
 
off_t Transparent_file::read_next()
60
 
{
61
 
  size_t bytes_read;
62
 
 
63
 
  /*
64
 
     No need to seek here, as the file managed by Transparent_file class
65
 
     always points to upper_bound byte
66
 
  */
67
 
  if ((bytes_read= internal::my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
68
 
    return (off_t) -1;
69
 
 
70
 
  /* end of file */
71
 
  if (!bytes_read)
72
 
    return (off_t) -1;
73
 
 
74
 
  lower_bound= upper_bound;
75
 
  upper_bound+= bytes_read;
76
 
 
77
 
  return lower_bound;
78
 
}
79
 
 
80
 
 
81
 
char Transparent_file::get_value(off_t offset)
82
 
{
83
 
  size_t bytes_read;
84
 
 
85
 
  /* check boundaries */
86
 
  if ((lower_bound <= offset) && (offset < upper_bound))
87
 
    return buff[offset - lower_bound];
88
 
 
89
 
  lseek(filedes, offset, SEEK_SET);
90
 
  /* read appropriate portion of the file */
91
 
  if ((bytes_read= internal::my_read(filedes, buff, buff_size,
92
 
                           MYF(0))) == MY_FILE_ERROR)
93
 
    return 0;
94
 
 
95
 
  lower_bound= offset;
96
 
  upper_bound= lower_bound + bytes_read;
97
 
 
98
 
  /* end of file */
99
 
  if (upper_bound == offset)
100
 
    return 0;
101
 
 
102
 
  return buff[0];
103
 
}