Vuo  2.0.0
VuoCompilerGenericType.cc
Go to the documentation of this file.
1 
11 #include "VuoGenericType.hh"
12 
13 
15 const string VuoCompilerGenericType::defaultBackingTypeName = "VuoInteger";
16 
17 
22 {
23  VuoGenericType::Compatibility compatibility;
24  vector<string> compatibleTypeNames = baseType->getCompatibleSpecializedTypes(compatibility);
25  string backingTypeName = VuoCompilerGenericType::chooseBackingTypeName(baseType->getModuleKey(), compatibleTypeNames);
26 
27  VuoCompilerType *backingType = getType(backingTypeName);
28  if (! backingType)
29  return NULL;
30 
31  return new VuoCompilerGenericType(baseType, backingType);
32 }
33 
37 VuoCompilerGenericType * VuoCompilerGenericType::newGenericType(VuoGenericType *baseType, const map<string, VuoCompilerType *> &types)
38 {
39  VuoCompilerType * (^getType)(string) = ^VuoCompilerType * (string moduleKey) {
40  map<string, VuoCompilerType *>::const_iterator typeIter = types.find(moduleKey);
41  return (typeIter != types.end() ? typeIter->second : NULL);
42  };
43 
44  return newGenericType(baseType, getType);
45 }
46 
50 VuoCompilerGenericType::VuoCompilerGenericType(VuoGenericType *baseType, VuoCompilerType *backingType)
51  : VuoCompilerType(backingType->getBase()->getModuleKey(), backingType->getModule())
52 {
53  setBase(baseType);
54  baseType->setCompiler(this);
55 }
56 
67 string VuoCompilerGenericType::chooseBackingTypeName(string genericTypeName, vector<string> compatibleTypeNames)
68 {
69  return (! compatibleTypeNames.empty() ?
70  compatibleTypeNames.front() :
71  VuoGenericType::replaceInnermostGenericTypeName(genericTypeName, defaultBackingTypeName));
72 }
73 
78 {
79  VuoGenericType *baseType = static_cast<VuoGenericType *>(getBase());
80  VuoGenericType::Compatibility compatibility;
81  return chooseBackingTypeName(baseType->getModuleKey(), baseType->getCompatibleSpecializedTypes(compatibility));
82 }