00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024 #ifndef SHCASTMANAGER_HPP
00025 #define SHCASTMANAGER_HPP
00026
00027 #include <map>
00028 #include "ShHashMap.hpp"
00029 #include "ShRefCount.hpp"
00030 #include "ShGraph.hpp"
00031 #include "ShTypeInfo.hpp"
00032
00033 namespace SH {
00034
00035 class ShVariant;
00036 class ShVariantCast;
00037
00066 struct ShCastMgrEdge;
00067 struct ShCastMgrVertex;
00068 typedef ShGraphType<ShCastMgrVertex, ShCastMgrEdge> ShCastMgrGraphType;
00069
00070 struct
00071 SH_DLLEXPORT
00072 ShCastMgrEdge: public ShGraphEdge<ShCastMgrGraphType>
00073 {
00074
00075
00076
00077 ShCastMgrEdge(const ShVariantCast *caster, bool automatic);
00078 ShCastMgrEdge(const ShCastMgrEdge &other);
00079
00080 std::ostream& graphvizDump(std::ostream& out) const;
00081
00082 const ShVariantCast *m_caster;
00083 bool m_auto;
00084 };
00085
00086 struct
00087 SH_DLLEXPORT
00088 ShCastMgrVertex: public ShGraphVertex<ShCastMgrGraphType>
00089 {
00090 ShCastMgrVertex(ShValueType valueType, ShDataType dataType);
00091 ShCastMgrVertex(const ShCastMgrVertex &other);
00092
00093 std::ostream& graphvizDump(std::ostream& out) const;
00094
00095 ShValueType m_valueType;
00096 ShDataType m_dataType;
00097 };
00098
00099 class
00100 SH_DLLEXPORT
00101 ShCastMgrGraph: public ShGraph<ShCastMgrGraphType>
00102 {
00103 public:
00104 ShCastMgrGraph();
00105
00106
00107 ShCastMgrVertex *addVertex(ShValueType valueType, ShDataType dataType);
00108
00109
00110
00111 void addEdge(ShCastMgrEdge* edge);
00112
00113 protected:
00114 typedef ShPairHashMap<ShValueType, ShDataType, ShCastMgrVertex*> VertexArray;
00115 VertexArray m_vert;
00116 };
00117
00118 class
00119 SH_DLLEXPORT
00120 ShCastManager {
00121 public:
00122 void addCast(const ShVariantCast *caster, bool automatic);
00123
00124
00125
00126 void init();
00127
00135 void doCast(ShVariant *dest, const ShVariant *src);
00136
00137
00145 bool doAllocCast(ShVariant *& dest, ShVariant *src,
00146 ShValueType valueType, ShDataType dataType);
00147 bool doAllocCast(const ShVariant *& dest, const ShVariant *src,
00148 ShValueType valueType, ShDataType dataType);
00149
00150
00151
00152
00153 int castDist(ShValueType destValueType, ShValueType srcValueType);
00154
00155 std::ostream& graphvizDump(std::ostream& out) const;
00156
00157 static ShCastManager* instance();
00158
00159 protected:
00160
00161 ShCastMgrGraph m_casts;
00162
00163
00164
00165
00166
00167
00168
00169 typedef ShPairPairHashMap<ShValueType, ShDataType, ShValueType, ShDataType,
00170 const ShVariantCast*> FirstCastMap;
00171
00172 typedef ShPairHashMap<ShValueType, ShValueType, int> CastDistMap;
00173
00174
00175 FirstCastMap m_castStep;
00176
00177
00178 CastDistMap m_autoDist;
00179
00180 static ShCastManager* m_instance;
00181 };
00182
00183 }
00184
00185 #endif