COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/SheetCell.h
Go to the documentation of this file.
00001 #ifndef COOPY_SHEETCELL_INC
00002 #define COOPY_SHEETCELL_INC
00003 
00004 #include <string>
00005 #include <coopy/RefCount.h>
00006 
00007 namespace coopy {
00008   namespace store {
00009     class SheetCell;
00010     class SheetCellMeta;
00011     class SheetCellSimpleMeta;
00012   }
00013 }
00014 
00015 enum {
00016   SHEET_CELL_NONE,
00017   SHEET_CELL_URL,
00018 };
00019 
00020 class coopy::store::SheetCellMeta : public RefCount {
00021 public:
00022   virtual ~SheetCellMeta() {
00023   }
00024 
00025   virtual bool getCode() const { return SHEET_CELL_NONE; }
00026 
00027   virtual bool isUrl() const { return false; }
00028 
00029   virtual std::string getUrl() const { return ""; }
00030 
00031   virtual std::string getText() const { return ""; }
00032 };
00033 
00034 class coopy::store::SheetCellSimpleMeta : public SheetCellMeta {
00035 public:
00036   std::string url, txt;
00037 
00038   virtual bool getCode() const { 
00039     return isUrl()?SHEET_CELL_URL:SHEET_CELL_NONE; 
00040   }
00041 
00042   virtual bool isUrl() const { return url!=""; }
00043 
00044   virtual std::string getUrl() const { return url; }
00045 
00046   virtual std::string getText() const { return txt; }
00047 };
00048 
00049 
00050 class coopy::store::SheetCell {
00051 public:
00052   std::string text;
00053   bool escaped;
00054   Poly<SheetCellMeta> meta;
00055 
00056   SheetCell() {
00057     escaped = true;
00058   }
00059 
00060   SheetCell(const char *text, bool escaped) : text(text), escaped(escaped) {
00061   }
00062 
00063   SheetCell(const std::string& text, bool escaped) : text(text), 
00064     escaped(escaped) {
00065   }
00066 
00067   SheetCell(int x);
00068 
00069   bool operator==(const SheetCell& alt) const {
00070     if (escaped!=alt.escaped) return false;
00071     return text==alt.text;
00072   }
00073 
00074   bool operator!=(const SheetCell& alt) const {
00075     if (escaped!=alt.escaped) return true;
00076     return text!=alt.text;
00077   }
00078   
00079   std::string toString() const {
00080     if (!meta.isValid()) {
00081       if (!escaped) {
00082         return text;
00083       }
00084       return std::string("{") + text + "}";
00085     }
00086     if (meta->isUrl()) {
00087       return std::string("url:") + meta->getUrl() + "::" + text;
00088     }
00089     return text;
00090   }
00091 
00092   int asInt() const;
00093   
00094   static SheetCell makeInt(int x);
00095 };
00096 
00097 #endif
00098 
00099 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines