COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libcoopy_core/include/coopy/TextBook.h
Go to the documentation of this file.
00001 #ifndef COOPY_TEXTBOOK
00002 #define COOPY_TEXTBOOK
00003 
00004 #include <coopy/PolySheet.h>
00005 #include <coopy/Property.h>
00006 #include <coopy/RefCount.h>
00007 #include <coopy/CompareFlags.h>
00008 
00009 #include <vector>
00010 #include <string>
00011 
00012 namespace coopy {
00013   namespace store {
00014     class TextBook;
00015   }
00016 }
00017 
00018 class coopy::store::TextBook : public RefCount {
00019 public:
00020   TextBook() {
00021     pool = 0/*NULL*/;
00022   }
00023 
00024   virtual ~TextBook() {}
00025 
00026   virtual std::vector<std::string> getNames() = 0;
00027 
00028   virtual int getSheetCount() {
00029     return (int)getNames().size();
00030   }
00031 
00032   virtual bool open(const Property& config) {
00033     return false;
00034   }
00035 
00036   virtual PolySheet readSheet(const std::string& name) = 0;
00037 
00038   virtual PolySheet readSheetByIndex(int index) {
00039     std::vector<std::string> names = getNames();
00040     if (index>=(int)names.size()) return PolySheet();
00041     return readSheet(names[index]);
00042   }
00043 
00044   virtual bool save(const char *fname, const char *format) {
00045     return false;
00046   }
00047 
00048   virtual bool inplace() const {
00049     return false;
00050   }
00051 
00052   virtual bool canWrite() const { return true; }
00053 
00054   bool operator==(const TextBook& alt) const {
00055     coopy::cmp::CompareFlags flags;
00056     return equals(alt,flags);
00057   }
00058 
00059   bool equals(const TextBook& alt, const coopy::cmp::CompareFlags& flags) const;
00060 
00061   virtual bool copy(const TextBook& alt, const Property& options);
00062 
00063   virtual bool addSheet(const SheetSchema& schema) {
00064     return false;
00065   }
00066 
00067   bool fixSchema(const SheetSchema& in,SimpleSheetSchema& out);
00068 
00069   virtual PolySheet provideSheet(const SheetSchema& schema);
00070 
00071   virtual std::string desc() const {
00072     return "TextBook";
00073   }
00074 
00075   virtual bool namedSheets() const {
00076     return true;
00077   }
00078 
00079   virtual TextBook& tail() {
00080     return *this;
00081   }
00082 
00083   virtual bool setPool(Pool *pool) {
00084     this->pool = pool;
00085     return true;
00086   }
00087 
00088   virtual Pool *getPool() const {
00089     return pool;
00090   }
00091 
00092   bool applyPool(DataSheet& sheet) {
00093     return sheet.setPool(getPool());
00094   }
00095 
00096   virtual bool isValid() const {
00097     return true;
00098   }
00099 
00100   virtual bool writtenToFuture() const {
00101     return false;
00102   }
00103 
00104   static bool exists(const char *fname);
00105 
00106   std::string toString() {
00107     std::string result;
00108     std::vector<std::string> names = getNames();
00109     for (int i=0; i<(int)names.size(); i++) {
00110       result += names[i];
00111       result += ":\n";
00112       result += readSheet(names[i]).toString();
00113       result += "\n";
00114     }
00115     return result;
00116   }
00117 
00118 private:
00119   Pool *pool;
00120 };
00121 
00122 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines