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