WORM 0.2
A C++ DAL/ORM code generation framework
|
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 00020 #ifndef WSQLTABLE_H 00021 #define WSQLTABLE_H 00022 00023 #include <string> 00024 #include <vector> 00025 00026 #include "wsqlcolumn.h" 00027 #include "wsqlforeignkey.h" 00028 #include "wsqlreferencedkey.h" 00029 00030 namespace WSql { 00031 00032 class WSqlTable 00033 { 00034 00035 public: 00036 enum Type{ 00037 NORMAL, 00038 VIEW, 00039 JOIN, 00040 TYPETABLE // tricky - see comments 00041 }; 00042 00043 WSqlTable(); 00044 WSqlTable(const std::string name); 00045 WSqlTable(const WSqlTable& other); 00046 virtual ~WSqlTable(); 00047 virtual WSqlTable& operator=(const WSqlTable& other); 00048 virtual bool operator==(const WSqlTable& other) const; 00049 inline bool operator!=(const WSqlTable &other) const { return !operator==(other); } 00050 00051 const std::string& name()const {return _name;} 00052 const std::string& className()const {return _className;} 00053 bool isEmpty()const; 00054 bool isValid()const{return _isValid;} 00055 int count() const; 00056 int indexOf(const std::string &columnname) const; 00057 const Type type()const{return _type;} 00058 00059 const std::string columnName(int i) const; 00060 WSqlColumn column(int i) const; 00061 WSqlColumn column(const std::string &name) const; 00062 const std::vector<WSqlColumn>& columns() const; 00063 std::vector<std::string> columnNames() const; 00064 00065 void setName(const std::string &n); 00066 void setClassName(const std::string &n){_className = n;} 00067 void setIsValid(bool b){_isValid = b;} 00068 void setType(Type t){_type=t;} 00069 void append(const WSqlColumn& column); 00070 void replace(int pos, const WSqlColumn& column); 00071 void insert(int pos, const WSqlColumn& column, bool replace=false); 00072 void remove(int pos); 00073 00074 void addForeignKey(const WSqlForeignKey & fk); 00075 void removeForeignKey(const WSqlForeignKey & fk); 00076 void removeForeignKey(int pos); 00077 void removeForeignKey(const std::string& columnname); 00078 00079 void addReferencedKey(const WSqlReferencedKey & rk); 00080 void removeReferencedKey(const WSqlReferencedKey & rk); 00081 void removeReferencedKey(int pos); 00082 void removeReferencedKey(const std::string& columnname); 00083 00084 bool hasForeignKeys()const{return ! _foreignKeys.empty();} 00085 bool hasReferencedKeys()const{return ! _referencedKeys.empty();} 00086 WSqlForeignKey foreignKey(const std::string columnname)const; 00087 WSqlReferencedKey referencedKey(const std::string columnname)const; 00088 const std::vector<WSqlForeignKey>& foreignKeys() const; 00089 const std::vector<WSqlReferencedKey>& referencedKeys() const; 00090 00091 protected: 00092 std::vector<WSqlColumn> _columns; 00093 std::vector<WSqlForeignKey> _foreignKeys; 00094 std::vector<WSqlReferencedKey> _referencedKeys; 00095 std::string _name; 00096 std::string _className; 00097 bool _isValid; 00098 Type _type; 00099 }; 00100 00101 } //namespace WSql 00102 00103 #endif // WSQLTABLE_H