Drizzled Public API Documentation

option_string.h
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2010 Vijay Samuel
5  * Copyright (C) 2008 MySQL
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #pragma once
23 
24 #include "client/client_priv.h"
25 #include <iosfwd>
26 #include <string>
27 #include <cstdlib>
28 #include <drizzled/gettext.h>
29 
31 {
32 public:
33  OptionString(char *in_string,
34  size_t in_length,
35  char *in_option,
36  size_t in_option_length,
37  OptionString *in_next) :
38  string(in_string),
39  length(in_length),
40  option(in_option),
41  option_length(in_option_length),
42  next(in_next)
43  { }
44 
45  OptionString() :
46  string(NULL),
47  length(0),
48  option(NULL),
49  option_length(0),
50  next(NULL)
51  { }
52 
53  ~OptionString()
54  {
55  if (getString())
56  free(getString());
57  if (getOption())
58  free(getOption());
59  }
60 
61  char *getString() const
62  {
63  return string;
64  }
65 
66  size_t getLength() const
67  {
68  return length;
69  }
70 
71  char *getOption() const
72  {
73  return option;
74  }
75 
76  size_t getOptionLength() const
77  {
78  return option_length;
79  }
80 
81  OptionString *getNext() const
82  {
83  return next;
84  }
85 
86  void setString(char *in_string)
87  {
88  string= in_string;
89  length= strlen(in_string);
90  }
91 
92  void setOption(char *in_option)
93  {
94  option= strdup(in_option);
95  option_length= strlen(in_option);
96  }
97 
98  void setNext(OptionString *in_next)
99  {
100  next= in_next;
101  }
102 
103 private:
104  char *string;
105  size_t length;
106  char *option;
107  size_t option_length;
108  OptionString *next;
109 };