COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/ColumnInfo.h
Go to the documentation of this file.
00001 #ifndef COOPY_COLUMNINFO
00002 #define COOPY_COLUMNINFO
00003 
00004 #include <string>
00005 #include <coopy/Property.h>
00006 
00007 namespace coopy {
00008   namespace store {
00009     class ColumnType;
00010     class ColumnInfo;
00011   }
00012 }
00013 
00017 class coopy::store::ColumnType {
00018 public:
00019   enum {
00020     COLUMN_FAMILY_NONE,
00021     COLUMN_FAMILY_INTEGER,
00022     COLUMN_FAMILY_REAL,
00023     COLUMN_FAMILY_TEXT,
00024     COLUMN_FAMILY_DATETIME,
00025     COLUMN_FAMILY_BOOLEAN,
00026     COLUMN_FAMILY_CURRENCY,
00027     COLUMN_FAMILY_BLOB,
00028 
00029     COLUMN_SOURCE_NONE,
00030     COLUMN_SOURCE_SQLITE,
00031     COLUMN_SOURCE_MYSQL,
00032     COLUMN_SOURCE_EXCEL,
00033     COLUMN_SOURCE_CSV,
00034     COLUMN_SOURCE_ACCESS,
00035   };
00036     
00037   std::string src_name;
00038   std::string src_lang;
00039   bool allowNull;
00040   int family;
00041   int src;
00042   int size;
00043   int size2;
00044   bool primaryKey;
00045   bool primaryKeySet;
00046   bool autoIncrement;
00047   bool autoIncrementSet;
00048 
00049   std::string foreignTable;
00050   std::string foreignKey;
00051   bool foreignKeySet;
00052 
00053   ColumnType() {
00054     reset();
00055   }
00056 
00057   ColumnType(const std::string& name) {
00058     setType(name);
00059   }
00060 
00061   void reset() {
00062     allowNull = true;
00063     family = COLUMN_FAMILY_NONE;
00064     src = COLUMN_SOURCE_NONE;
00065     size = 0;
00066     size2 = 0;
00067     primaryKey = false;
00068     primaryKeySet = false;
00069     src_lang = "";
00070     src_name = "";
00071     autoIncrement = false;
00072     autoIncrementSet = false;
00073     foreignKeySet = false;
00074   }
00075 
00076   // do guess-work
00077   bool setType(const std::string& name, const std::string& lang = "unknown");
00078 
00079   std::string asSqlite(bool addPrimaryKey) const;
00080 };
00081 
00082 
00086 class coopy::store::ColumnInfo {
00087 private:
00088   std::string name;
00089   bool nameSet;
00090   ColumnType columnType;
00091   bool typeSet;
00092 public:
00093   ColumnInfo() : nameSet(false), typeSet(false) {}
00094   ColumnInfo(std::string name) : name(name), nameSet(true), typeSet(false) {}
00095   ColumnInfo(std::string name, const ColumnType& t) : name(name), nameSet(true), typeSet(true), columnType(t) {}
00096   
00097   virtual ~ColumnInfo() {}
00098   
00099   virtual bool hasName() const { return nameSet; }
00100   
00101   virtual std::string getName() const { return name; }
00102 
00103   virtual bool hasPrimaryKey() const { return columnType.primaryKeySet; }
00104   
00105   virtual bool isPrimaryKey() const { return columnType.primaryKey; }
00106   
00107   virtual bool hasForeignKey() const { return columnType.foreignKeySet; }
00108 
00109   virtual bool isForeignKey() const { return columnType.foreignKey!=""; }
00110     
00111   const ColumnType& getColumnType() const { return columnType; }
00112 
00113   virtual bool hasType() const { return typeSet; }
00114 
00115   void setName(std::string name) {
00116     this->name = name;
00117     nameSet = true;
00118   }
00119 
00120   void setPk(bool pk) {
00121     columnType.primaryKeySet = true;
00122     columnType.primaryKey = pk;
00123   }
00124 
00125   void setAutoIncrement(bool ai) {
00126     columnType.autoIncrementSet = true;
00127     columnType.autoIncrement = ai;
00128   }
00129 
00130   void setReference(std::string t, std::string c) {
00131     columnType.foreignKeySet = true;
00132     columnType.foreignTable = t;
00133     columnType.foreignKey = c;    
00134   }
00135 
00136   void setType(const std::string name, const std::string lang = "unknown") {
00137     columnType.setType(name,lang);
00138     typeSet = true;
00139   }
00140 };
00141 
00142 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines