]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/engine/TypeCode.hxx
Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / TypeCode.hxx
index 430320c8df9a6a35904729a435e4c78946ec2b8c..222f865c64ab43fb1ef5fd471d006a0bc30a46e7 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef __TYPECODE_HXX__
 #define __TYPECODE_HXX__
 
-//#include <Python.h> // here, to avoid warning: "_POSIX_C_SOURCE" redefined
-
+#include "RefCounter.hxx"
 #include "Exception.hxx"
+#include "Any.hxx"
 
 #include <string>
 #include <list>
@@ -12,91 +12,207 @@ namespace YACS
 {
   namespace ENGINE
   {
+    class Visitor;
 
     typedef enum
       {
-       None     = 0,
-       Double   = 1,
-       Int      = 2,
-       String   = 3,
-       Bool     = 4,
-       Objref   = 5,
-       Sequence = 6
+        None     = 0,
+        Double   = 1,
+        Int      = 2,
+        String   = 3,
+        Bool     = 4,
+        Objref   = 5,
+        Sequence = 6,
+        Array    = 7,
+        Struct   = 8
       } DynType;
 
 //     typedef enum DynType StreamType;
 
-    class TypeCode_objref;
-
-    class TypeCode
+    class TypeCodeObjref;
+
+/*! \brief Base class for all type objects.
+ *
+ * \ingroup TypeCodes
+ *
+ * All type objects should be a subclass of TypeCode.  Some type objects,
+ * TypeCodeObjref for example, represent one individual type.  Other type
+ * objects, such as TypeCodeSeq, are composite types (sequence, here)
+ *
+ * \see TypeCodeObjref
+ * \see TypeCodeSeq
+ * \see TypeCodeStruct
+ * \see TypeCodeArray
+ */
+    class TypeCode : public RefCounter
     {
     public:
       TypeCode(DynType kind);
-      virtual ~TypeCode();
 
       DynType kind() const;
-
+      const char * getKindRepr() const;
+      
+      virtual TypeCode *clone() const;
+      virtual void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
+      virtual void destroyZippedAny(char *data) const;
+      virtual AnyPtr getOrBuildAnyFromZippedData(char *data) const;
       virtual const char * name()       const throw(Exception);
+      virtual const char * shortName()  const;
       virtual const char * id()         const throw(Exception);
-      virtual TypeCode * content_type() const throw(Exception);
-      virtual int is_a(const char* repositoryId);
-      virtual int is_a(TypeCode* tc);
-
-      static TypeCode * interface_tc(const char* id, const char* name);
-      static TypeCode * interface_tc(const char* id, const char* name, std::list<TypeCode_objref *> ltc);
-      static TypeCode * sequence_tc (const char* id, const char* name, TypeCode *content);
+      virtual const TypeCode * contentType() const throw(Exception);
+      virtual int isA(const char* repositoryId) const throw(Exception);
+      virtual int isA(const TypeCode* tc) const ;
+      virtual int isAdaptable(const TypeCode* tc) const;
+      virtual unsigned getSizeInByteOfAnyReprInSeq() const;
+
+      static const char *getKindRepr(DynType kind);
+      static TypeCode * interfaceTc(const char* id, const char* name);
+      static TypeCode * interfaceTc(const char* id, const char* name, const std::list<TypeCodeObjref *>& ltc);
+      static TypeCode * sequenceTc (const char* id, const char* name, TypeCode *content);
+      static TypeCode * structTc (const char* id, const char* name);
 
     protected:
       // --- These operators are placed here to avoid them being used externally
       TypeCode(const TypeCode& tc);
       TypeCode& operator=(const TypeCode& tc);
-      TypeCode() {}
-
+      virtual ~TypeCode();
+    protected:
       DynType _kind;
+      static const char *KIND_STR_REPR [];
     };
 
 
-    class TypeCode_objref: public TypeCode
+/*! \brief Class for reference objects.
+ *
+ * \ingroup TypeCodes
+ *
+ */
+    class TypeCodeObjref: public TypeCode
     {
+      friend class Visitor;
     public:
-      TypeCode_objref(const char* repositoryId, const char* name);
+      TypeCodeObjref(const char* repositoryId, const char* name);
 
-      TypeCode_objref(const char* repositoryId, const char* name, std::list<TypeCode_objref *> ltc);
-      virtual ~TypeCode_objref();
+      TypeCodeObjref(const char* repositoryId, const char* name, const std::list<TypeCodeObjref *>& ltc);
 
+      TypeCode *clone() const;
+      void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
+      void destroyZippedAny(char *data) const;
+      AnyPtr getOrBuildAnyFromZippedData(char *data) const;
       const char * id() const   throw(Exception);
       const char * name() const throw(Exception);
-      int is_a(const char* repositoryId) throw(Exception);
-      virtual int is_a(TypeCode* tc) throw(Exception);
-
+      const char * shortName() const;
+      int isA(const char* repositoryId) const throw(Exception);
+      virtual int isA(const TypeCode* tc) const ;
+      virtual int isAdaptable(const TypeCode* tc) const;
+    protected:
+      ~TypeCodeObjref();
+      TypeCodeObjref(const TypeCodeObjref& other);
     private:
-      TypeCode_objref() {}
-
       std::string _name;
+      std::string _shortName;
       std::string _repoId;
-      std::list<TypeCode_objref *> _listOfBases;
+      std::list<TypeCodeObjref *> _listOfBases;
     };
 
 
-    class TypeCode_seq: public TypeCode
+/*! \brief Class for sequence objects.
+ *
+ * \ingroup TypeCodes
+ *
+ */
+    class TypeCodeSeq: public TypeCode
     {
     public:
-      TypeCode_seq(const char* repositoryId, const char* name, TypeCode *content);
-      virtual ~TypeCode_seq();
+      TypeCodeSeq(const char* repositoryId, const char* name, const TypeCode *content);
 
+      TypeCode *clone() const;
+      void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
+      void destroyZippedAny(char *data) const;
+      AnyPtr getOrBuildAnyFromZippedData(char *data) const;
       const char * id()   const throw(Exception);
       const char * name() const throw(Exception);
+      const char * shortName() const;
+
+      virtual const TypeCode * contentType() const throw(Exception);
+      virtual int isA(const TypeCode* tc) const ;
+      virtual int isAdaptable(const TypeCode* tc) const;
+    protected:
+      ~TypeCodeSeq();
+      TypeCodeSeq(const TypeCodeSeq& tc);
+    private:
+      std::string _name;
+      std::string _shortName;
+      std::string _repoId;
+      const TypeCode  *_content;
+    };
 
-      virtual TypeCode * content_type() const throw(Exception);
-      virtual int is_a(TypeCode* tc);
+/*! \brief Class for array objects.
+ *
+ * \ingroup TypeCodes
+ *
+ */
+    class TypeCodeArray : public TypeCode
+    {
+    public:
+      TypeCodeArray(const char* repositoryId, const char* name, const TypeCode *content, unsigned staticLgth);
+      TypeCode *clone() const;
+      void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
+      void destroyZippedAny(char *data) const;
+      AnyPtr getOrBuildAnyFromZippedData(char *data) const;
+      const char * id()   const throw(Exception);
+      const char * name() const throw(Exception);
+      const char * shortName() const;
+      unsigned getStaticLgth() const;
 
+      virtual const TypeCode * contentType() const throw(Exception);
+      virtual int isA(const TypeCode* tc) const ;
+      virtual int isAdaptable(const TypeCode* tc) const;
+      unsigned getSizeInByteOfAnyReprInSeq() const;
+    protected:
+      ~TypeCodeArray();
+      TypeCodeArray(const TypeCodeArray& tc);
     private:
-      TypeCode_seq() {}
+      std::string _name;
+      std::string _shortName;
+      std::string _repoId;
+      unsigned _staticLgth;
+      const TypeCode  *_content;
+    };
 
+/*! \brief Class for struct type.
+ *
+ * \ingroup TypeCodes
+ *
+ */
+    class TypeCodeStruct : public TypeCode
+    {
+    public:
+      TypeCodeStruct(const char* repositoryId, const char* name);
+      TypeCode *clone() const;
+      void putReprAtPlace(char *pt, const char *val, bool deepCpy) const;
+      void destroyZippedAny(char *data) const;
+      AnyPtr getOrBuildAnyFromZippedData(char *data) const;
+      const char * id() const   throw(Exception);
+      const char * name() const throw(Exception);
+      const char * shortName() const;
+      virtual int isA(const char* repositoryId) const throw(Exception);
+      virtual int isA(const TypeCode* tc) const ;
+      virtual int isAdaptable(const TypeCode* tc) const;
+      virtual void addMember(const std::string& name,TypeCode* tc);
+      int memberCount() const;
+      const char*  memberName(int index) const;
+      TypeCode*  memberType(int index) const;
+    protected:
+      ~TypeCodeStruct();
+      TypeCodeStruct(const TypeCodeStruct& tc);
+    private:
       std::string _name;
+      std::string _shortName;
       std::string _repoId;
-      TypeCode  * _content;
+      std::vector< std::pair<std::string,TypeCode*> > _members;
     };
+
   }
 }
 #endif