Drizzled Public API Documentation

option_string.h
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Vijay Samuel
00005  *  Copyright (C) 2008 MySQL
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #pragma once
00023 
00024 #include "client_priv.h"
00025 #include <iosfwd>
00026 #include <string>
00027 #include <cstdlib>
00028 #include <drizzled/gettext.h>
00029 
00030 class OptionString 
00031 {
00032 public:
00033   OptionString(char *in_string,
00034                size_t in_length,
00035                char *in_option,
00036                size_t in_option_length,
00037                OptionString *in_next) :
00038     string(in_string),
00039     length(in_length),
00040     option(in_option),
00041     option_length(in_option_length),
00042     next(in_next)
00043   { }  
00044 
00045   OptionString() :
00046     string(NULL),
00047     length(0),
00048     option(NULL),
00049     option_length(0),
00050     next(NULL)
00051   { }
00052 
00053   ~OptionString()
00054   {
00055     if (getString())
00056       free(getString());
00057     if (getOption())
00058       free(getOption());
00059   }
00060 
00061   char *getString() const
00062   {
00063     return string;
00064   }
00065 
00066   size_t getLength() const
00067   {
00068     return length;
00069   }
00070 
00071   char *getOption() const
00072   {
00073   return option;
00074   }
00075 
00076   size_t getOptionLength() const
00077   {
00078     return option_length;
00079   }
00080 
00081   OptionString *getNext() const
00082   {
00083     return next;
00084   }
00085 
00086   void setString(char *in_string)
00087   {
00088     string= in_string;
00089     length= strlen(in_string);
00090   }
00091 
00092   void setOption(char *in_option)
00093   {
00094     option= strdup(in_option);
00095     option_length= strlen(in_option);
00096   }
00097 
00098   void setNext(OptionString *in_next)
00099   {
00100     next= in_next;
00101   }
00102   
00103 private:
00104   char *string;
00105   size_t length;
00106   char *option;
00107   size_t option_length;
00108   OptionString *next;
00109 };