COOPY » Guide
version 0.6.5
|
00001 #ifndef COOPY_COMPAREFLAGS 00002 #define COOPY_COMPAREFLAGS 00003 00004 #include <stdio.h> 00005 #include <vector> 00006 #include <set> 00007 #include <string> 00008 00009 #include <coopy/Pool.h> 00010 00011 namespace coopy { 00012 namespace cmp { 00013 class CompareFlags; 00014 class CompareOutput; 00015 } 00016 namespace store { 00017 // forward declarations 00018 class DataSheet; 00019 class TextBook; 00020 } 00021 } 00022 00026 class coopy::cmp::CompareOutput { 00027 public: 00028 FILE *out; 00029 00030 CompareOutput() { 00031 out = stdout; 00032 } 00033 00034 CompareOutput(const char *fname) { 00035 out = stdout; 00036 setOutput(fname); 00037 } 00038 00039 ~CompareOutput() { 00040 setOutput(NULL); 00041 } 00042 00043 bool setOutput(const char *fname) { 00044 if (out!=stdout) { 00045 fclose(out); 00046 out = stdout; 00047 } 00048 if (fname==NULL) return true; 00049 out = fopen(fname,"wb"); 00050 return (out!=NULL); 00051 } 00052 }; 00053 00057 class coopy::cmp::CompareFlags { 00058 public: 00059 bool head_trimmed; 00060 bool tail_trimmed; 00061 FILE *out; 00062 std::set<std::string> tables; 00063 std::set<std::string> acts; 00064 std::vector<std::string> ordered_tables; 00065 std::vector<std::string> ids; 00066 std::vector<std::string> coined; 00067 std::vector<std::string> include_columns; 00068 std::vector<std::string> exclude_columns; 00069 std::vector<int> ids_local; 00070 std::vector<int> ids_remote; 00071 bool trust_ids; 00072 bool bias_ids; 00073 bool trust_column_names; 00074 coopy::store::DataSheet *mapping; 00075 coopy::store::TextBook *mapping_book; 00076 coopy::store::TextBook *meta_book; 00077 bool pivot_sides_with_local; 00078 bool has_pivot; 00079 bool use_order; 00080 bool omit_format_name; 00081 bool omit_sheet_name; 00082 bool fixed_columns; 00083 bool assume_header; 00084 bool ignore_case; 00085 bool create_unknown_sheets; 00086 bool clean_sheets; 00087 std::string pivot_uri; 00088 std::string local_uri; 00089 std::string remote_uri; 00090 bool resolving; 00091 std::string resolve; 00092 std::string variant; 00093 coopy::store::Pool *pool; 00094 bool foreign_pool; 00095 bool foreign_pool_set; 00096 bool offload_to_sql_when_possible; 00097 int context_lines; 00098 00099 CompareFlags() { 00100 head_trimmed = false; 00101 tail_trimmed = false; 00102 out = stdout; 00103 trust_ids = false; 00104 bias_ids = false; 00105 trust_column_names = false; 00106 mapping = 0 /*NULL*/; 00107 mapping_book = 0 /*NULL*/; 00108 pivot_sides_with_local = false; 00109 use_order = true; 00110 omit_format_name = false; 00111 omit_sheet_name = false; 00112 fixed_columns = false; 00113 ignore_case = false; 00114 resolving = false; 00115 has_pivot = true; 00116 assume_header = true; 00117 pool = 0 /*NULL*/; 00118 foreign_pool = false; 00119 foreign_pool_set = false; 00120 meta_book = 0 /*NULL*/; 00121 create_unknown_sheets = false; 00122 clean_sheets = false; 00123 offload_to_sql_when_possible = false; 00124 context_lines = -2; // use default 00125 } 00126 00127 // js build has problem with implicit copy 00128 CompareFlags(const CompareFlags& alt) { 00129 copy(alt); 00130 } 00131 00132 const CompareFlags& operator= (const CompareFlags& alt) { 00133 setOutput(0/*NULL*/); 00134 copy(alt); 00135 return *this; 00136 } 00137 00138 ~CompareFlags() { 00139 setOutput(NULL); 00140 } 00141 00142 bool setOutput(const CompareOutput& o) { 00143 out = o.out; 00144 return true; 00145 } 00146 00147 bool canInsert() const { 00148 if (acts.size()==0) return true; 00149 return acts.find("insert")!=acts.end(); 00150 } 00151 00152 bool canDelete() const { 00153 if (acts.size()==0) return true; 00154 return acts.find("delete")!=acts.end(); 00155 } 00156 00157 bool canUpdate() const { 00158 if (acts.size()==0) return true; 00159 return acts.find("update")!=acts.end(); 00160 } 00161 00162 bool canSchema() const { 00163 if (acts.size()==0) return true; 00164 return acts.find("schema")!=acts.end(); 00165 } 00166 private: 00167 void copy(const CompareFlags& alt); 00168 }; 00169 00170 #endif 00171