UGDK
src/ugdk/util/gdd/descriptionprotocol.h
Go to the documentation of this file.
00001 
00002 
00003 #ifndef UGDK_UTIL_DESCRIPTIONPROTOCOL_H_
00004 #define UGDK_UTIL_DESCRIPTIONPROTOCOL_H_
00005 
00006 #include <string>
00007 #include <vector>
00008 #include <ugdk/util/gdd/abstractloader.h>
00009 #include <cstdio>
00010 
00011 namespace ugdk {
00012 
00013 namespace gdd {
00014 
00015 typedef std::string               GDDString;
00016 typedef std::vector<GDDString>    GDDArgs;
00017 
00018 class LoadError {
00019   public:
00020     enum Type {
00021         TYPE_MISMATCH,
00022         INVALID_VALUE
00023     };
00024 };
00025 
00026 template <class T>
00027 class DescriptionProtocol {
00028 
00029   public:
00030 
00031     virtual ~DescriptionProtocol() {}
00032 
00033     void set_loader(AbstractLoader<T> *loader) { loader_ = loader; }
00034 
00035     AbstractLoader<T>* loader() const { return loader_; }
00036 
00037     virtual bool NewDescription() = 0;
00038 
00039     virtual bool NewData(const GDDString& data_name) = 0;
00040 
00041     virtual bool NewProperty(const GDDString& property_name,
00042                              const GDDArgs& property_args) = 0;
00043 
00044     virtual bool NewRing(const GDDString& ring_typename) = 0;
00045 
00046     virtual bool NewEntry(const GDDString& entry_name, const GDDArgs& entry_args) = 0;
00047 
00048     virtual bool NewSimpleChain(const GDDString& ring_typename,
00049                                   const GDDArgs& ring_args) = 0;
00050 
00051   protected:
00052 
00053     DescriptionProtocol() : loader_(NULL) {}
00054 
00055     void error(LoadError::Type error_type, std::string &msg = "") {
00056         switch (error_type) {
00057           case LoadError::TYPE_MISMATCH:
00058             fprintf(stderr, "Load Error: type mismatch. %s\n", msg.c_str());
00059             break;
00060           case LoadError::INVALID_VALUE:
00061             fprintf(stderr, "Load Error: invalid value. %s\n", msg.c_str());
00062             break;
00063           default:
00064             fprintf(stderr, "Load Error: unknown. %s\n", msg.c_str()); // \comofas
00065             break;
00066         }
00067     }
00068 
00069   private:
00070 
00071     AbstractLoader<T>   *loader_;
00072 
00073 };
00074 
00075 } /* namespace gdd */
00076 
00077 } /* namespace ugdk */
00078 
00079 #endif /* UGDK_UTIL_DESCRIPTIONPROTOCOL_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines