COOPY » Guide
version 0.6.5
|
00001 #ifndef FORMAT_DESC_INC 00002 #define FORMAT_DESC_INC 00003 00004 #include <coopy/Property.h> 00005 00006 #include <vector> 00007 #include <string> 00008 00009 namespace coopy { 00010 namespace store { 00011 class FormatDesc; 00012 } 00013 } 00014 00020 class coopy::store::FormatDesc { 00021 public: 00022 std::string name; 00023 00024 FormatDesc(const char *name) : name(name) { 00025 } 00026 00027 class Extension { 00028 public: 00029 std::string ext; 00030 std::string notes; 00031 Extension(const char *ext, const char *notes) : ext(ext), notes(notes) {} 00032 }; 00033 00034 class Dbi { 00035 public: 00036 std::string ex; 00037 std::string notes; 00038 Dbi(const char *ex, const char *notes) : ex(ex), notes(notes) {} 00039 }; 00040 00041 class Option { 00042 public: 00043 std::string tag; 00044 PolyValue val; 00045 std::string notes; 00046 bool opt; 00047 00048 Option(const char *tag, PolyValue val, const char *notes, bool opt) : 00049 tag(tag), val(val), notes(notes), opt(opt) {} 00050 }; 00051 00052 std::vector<Extension> exts; 00053 std::vector<Option> opts; 00054 std::vector<Dbi> dbis; 00055 00056 void addExtension(const char *ext, const char *notes) { 00057 exts.push_back(Extension(ext,notes)); 00058 } 00059 void addDbi(const char *ext, const char *notes) { 00060 dbis.push_back(Dbi(ext,notes)); 00061 } 00062 void addOption(const char *tag, PolyValue val, const char *notes, bool opt) { 00063 opts.push_back(Option(tag,val,notes,opt)); 00064 } 00065 00066 std::string toString() { 00067 std::string result = ""; 00068 if (exts.size()>0) { 00069 result += " This format is activated for files with the following extensions:\n"; 00070 for (int i=0; i<(int)exts.size(); i++) { 00071 result += " extension: "; 00072 result += exts[i].ext; 00073 if (exts[i].notes!="") { 00074 result += " ("; 00075 result += exts[i].notes; 00076 result += ")"; 00077 } 00078 result += "\n"; 00079 } 00080 } 00081 if (opts.size()>0) { 00082 result += " This format is activated for a .json file like this example:\n"; 00083 result += " {\n"; 00084 for (int i=0; i<(int)opts.size(); i++) { 00085 Option& o = opts[i]; 00086 result += " \""; 00087 result += o.tag; 00088 result += "\": "; 00089 PolyValue v = o.val; 00090 if (o.val.isString()) { 00091 result += "\""; 00092 } 00093 result += o.val.asString(); 00094 if (o.val.isString()) { 00095 result += "\""; 00096 } 00097 if (i<(int)opts.size()-1) { 00098 result += ","; 00099 } 00100 result += "\n"; 00101 } 00102 result += " }\n"; 00103 } 00104 if (dbis.size()>0) { 00105 result += " This format is activated for references starting with 'dbi:' such as:\n"; 00106 for (int i=0; i<(int)dbis.size(); i++) { 00107 result += " "; 00108 result += dbis[i].ex; 00109 if (dbis[i].notes!="") { 00110 result += " ("; 00111 result += dbis[i].notes; 00112 result += ")"; 00113 } 00114 result += "\n"; 00115 } 00116 } 00117 return result; 00118 } 00119 00120 void show() { 00121 printf("%s\n%s\n", name.c_str(),toString().c_str()); 00122 } 00123 }; 00124 00125 #endif 00126