Drizzled Public API Documentation

metadata_ms.h
00001 /* Copyright (C) 2009 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Barry Leslie
00020  *
00021  * 2009-01-09
00022  *
00023  * H&G2JCtL
00024  *
00025  * PBMS Meta Data utilities.
00026  *
00027  */
00028 #pragma once
00029 #ifndef __METADATA_MS_H__
00030 #define __METADATA_MS_H__
00031 
00032 #ifdef DRIZZLED
00033 #include <drizzled/internal/m_string.h>
00034 #include <drizzled/charset_info.h>
00035 #else
00036 #include "m_ctype.h"
00037 #endif
00038  
00039 #include "pbmslib.h"
00040 
00041 class MetaData
00042 {
00043 private:
00044   char *data;
00045   char *eod;
00046   char *position;
00047   
00048 public:
00049   MetaData(): data(NULL), eod(NULL), position(NULL){}
00050   MetaData(char *meta_data, size_t meta_data_size): data(meta_data), eod(meta_data + meta_data_size), position(meta_data){}
00051   
00052   char *getBuffer() { return data;}
00053     
00054   void use_data(char *meta_data, size_t meta_data_size) 
00055   {
00056     data = meta_data;
00057     position = data;
00058     eod = data + meta_data_size;
00059   }
00060   
00061   void reset() 
00062   {
00063     position = data;
00064   }
00065   
00066   char *findNext(char **value)
00067   {
00068     char *name = position;
00069     if (position >= eod)
00070       return NULL;
00071       
00072     position += strlen(position) +1;
00073     if (position >= eod)
00074       return NULL;
00075       
00076     *value = position;
00077     position += strlen(position) +1;
00078     
00079     return name;
00080   }
00081   
00082   char *findName(const char *name)
00083   {
00084     char  *metadata = data;
00085     
00086     while (metadata < eod && my_strcasecmp(&my_charset_utf8_general_ci, metadata, name)) {
00087       metadata += strlen(metadata) +1;
00088       metadata += strlen(metadata) +1;
00089     }
00090     
00091     if (metadata < eod)
00092       return metadata + strlen(metadata) +1;
00093       
00094     return NULL;
00095   }
00096   
00097   char *findNamePosition(const char *name)
00098   {
00099     char  *metadata = data;
00100     
00101     while (metadata < eod && my_strcasecmp(&my_charset_utf8_general_ci, metadata, name)) {
00102       metadata += strlen(metadata) +1;
00103       metadata += strlen(metadata) +1;
00104     }
00105     
00106     if (metadata < eod)
00107       return metadata;
00108       
00109     return NULL;
00110   }
00111   
00112 #ifdef HAVE_ALIAS_SUPPORT
00113   char *findAlias() {return findName(MS_ALIAS_TAG);}
00114 #endif
00115   
00116   static uint32_t recSize(const char *rec) 
00117   { 
00118     uint32_t len = strlen(rec) + 1;
00119     
00120     rec += len;
00121     return (len + strlen(rec) + 1);
00122   }
00123   
00124 };
00125 #endif //__METADATA_MS_H__