[r1]: trunk / Cm / Cm.Core / Util.cpp Maximize Restore History

Download this file

Util.cpp    117 lines (98 with data), 2.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <Cm.Core/Util.hpp>
#include <Cm.Core/Pointer.hpp>
#include <Cm.Core/Namespace.hpp>
#include <Cm.Core/BasicType.hpp>
#include <Cm.Core/Assert.hpp>
namespace Cm { namespace Core {
class TypeIdFactory;
typedef boost::shared_ptr<TypeIdFactory> TypeIdFactoryPtr;
class TypeIdFactory
{
public:
static void Init();
static void Done();
static TypeIdFactoryPtr Instance();
int GetNextTypeId() { return nextTypeId++; }
private:
static TypeIdFactoryPtr instance;
TypeIdFactory(): nextTypeId(FIRST_USER_TYPEID) {}
int nextTypeId;
};
TypeIdFactoryPtr TypeIdFactory::instance;
void TypeIdFactory::Init()
{
instance = TypeIdFactoryPtr(new TypeIdFactory());
}
void TypeIdFactory::Done()
{
instance.reset();
}
TypeIdFactoryPtr TypeIdFactory::Instance()
{
CM_CORE_ASSERT(instance);
return instance;
}
int GetNextTypeId()
{
return TypeIdFactory::Instance()->GetNextTypeId();
}
String GetConstructorFunctionSetName()
{
return ".constructor";
}
String GetAssignmentFunctionSetName()
{
return ".assign";
}
void AppendParameterTypeNames(String& name, const ParameterList& parameters)
{
int n = parameters.Count();
for (int i = 0; i < n; ++i)
{
if (i > 0)
{
name.append(", ");
}
EntityPtr typeExpr = parameters[i]->TypeExpr();
TypePtr type = typeExpr->GetType();
String typeName = type ? type->FullName() : typeExpr->FullName();
name.append(typeName);
}
}
String MakeOverloadName(const String& functionSetName, const ParameterListPtr& parameters)
{
String name(functionSetName);
name.append("(");
AppendParameterTypeNames(name, *parameters);
name.append(")");
return name;
}
String MakeOverloadName(const String& functionSetName, const ArgumentVector& arguments)
{
String name(functionSetName);
name.append("(");
int n = arguments.size();
for (int i = 0; i < n; ++i)
{
if (i > 0)
{
name.append(", ");
}
name.append(arguments[i].Type()->FullName());
}
name.append(")");
return name;
}
String MakeConversionName(const String& sourceTypeName, const String& targetTypeName)
{
return sourceTypeName + " -> " + targetTypeName;
}
void UtilInit()
{
TypeIdFactory::Init();
}
void UtilDone()
{
TypeIdFactory::Done();
}
} } // namespoace Cm::Core