WORM 0.2
A C++ DAL/ORM code generation framework

src/sql/wsqlrecord.h

Go to the documentation of this file.
00001 /*
00002  *    WORM - a DAL/ORM code generation framework
00003  *    Copyright (C) 2011  Erik Winn <erikwinnmail@yahoo.com>
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 3 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, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef WSQLRECORD_H
00020 #define WSQLRECORD_H
00021 
00022 #include <string>
00023 
00024 #include "wsqltable.h"
00025 #include "wsqlfield.h"
00026 
00027 namespace WSql
00028 {
00029 
00030 class WSqlRecord
00031 {
00032     public:
00033         WSqlRecord();
00034         WSqlRecord( const WSqlRecord& other );
00035         WSqlRecord& operator=( const WSqlRecord& other );
00036         ~WSqlRecord();
00037 
00038         bool operator==( const WSqlRecord &other ) const;
00039         inline bool operator!=( const WSqlRecord &other ) const { return !operator==( other ); }
00040         inline std::string operator[](const std::string fieldname)const{return data(fieldname);}
00041         std::string operator[](const char* fieldname)const{return operator[](std::string(fieldname));}
00042         
00043         inline void append(WSqlField field){_fields.push_back(field);}
00044         
00045         WSqlField at( int pos ) const;
00046         WSqlField field( int pos ) const;
00047         WSqlField field( const std::string& colname ) const;
00048         std::string data( int pos ) const;
00049         std::string data( const std::string& colname ) const;
00050         bool isNull( int i ) const;
00051         bool isNull( const std::string& name ) const;
00052         int indexOf(const std::string& name)const;
00053         inline bool isValid()const{return _isValid;}
00054         inline bool empty(){return _fields.empty();}
00055         inline int size()const{return _fields.size();}
00056         inline int count()const{return _fields.size();}
00057         
00059         //JUST rushing .. fixme.
00060         const std::vector<WSqlField>& fields() const {return _fields;};
00061         
00063 //             if ( pos > _fields.size() ) {
00064 //                 return;
00065 //             }
00066 // 
00067 //         };
00068 //         template <typename T> void setData( T t, std::string colname ) {
00069 //             if ( ! t ) {
00070 //                 return;
00071 //             }
00072 // 
00073 //         };
00074 
00075         void setNull( int i );
00076         void setNull( const std::string& name );
00077 
00078         void clear();
00079         
00080     private:
00081         bool _isValid;
00082         std::vector<WSqlField>::const_iterator const_cur_field_it;
00083         std::vector<WSqlField>::iterator field_it;
00084 
00086         std::vector<WSqlField> _fields;
00087 };
00088 
00089 } //namespace WSql
00090 
00091 #endif // WSQLRECORD_H
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines