本文整理汇总了C++中AnyType::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ AnyType::GetType方法的具体用法?C++ AnyType::GetType怎么用?C++ AnyType::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyType
的用法示例。
在下文中一共展示了AnyType::GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tptS_delete
AnyType TPTScriptInterface::tptS_delete(std::deque<std::string> * words)
{
//Arguments from stack
AnyType partRef = eval(words);
Simulation * sim = m->GetSimulation();
if(partRef.GetType() == TypePoint)
{
ui::Point deletePoint = ((PointType)partRef).Value();
if(deletePoint.X<0 || deletePoint.Y<0 || deletePoint.Y >= YRES || deletePoint.X >= XRES)
throw GeneralException("Invalid position");
sim->delete_part(deletePoint.X, deletePoint.Y);
}
else if(partRef.GetType() == TypeNumber)
{
int partIndex = ((NumberType)partRef).Value();
if(partIndex < 0 || partIndex >= NPART)
throw GeneralException("Invalid particle index");
sim->kill_part(partIndex);
}
else
throw GeneralException("Invalid particle reference");
return NumberType(0);
}
示例2: tptS_create
AnyType TPTScriptInterface::tptS_create(std::deque<std::string> * words)
{
//Arguments from stack
AnyType createType = eval(words);
PointType position = eval(words);
Simulation * sim = m->GetSimulation();
int type;
if(createType.GetType() == TypeNumber)
type = ((NumberType)createType).Value();
else if(createType.GetType() == TypeString)
type = GetParticleType(((StringType)createType).Value());
else
throw GeneralException("Invalid type");
if(type == -1)
throw GeneralException("Invalid particle type");
ui::Point tempPoint = position.Value();
if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
throw GeneralException("Invalid position");
int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type);
return NumberType(returnValue);
}
示例3: tptS_set
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
//Arguments from stack
StringType property = eval(words);
AnyType selector = eval(words);
AnyType value = eval(words);
Simulation * sim = m->GetSimulation();
unsigned char * partsBlock = (unsigned char*)&sim->parts[0];
int returnValue = 0;
FormatType propertyFormat;
int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat);
if(propertyOffset==-1)
throw GeneralException("Invalid property");
//Selector
int newValue;
float newValuef;
if (value.GetType() == TypeNumber)
{
newValue = newValuef = ((NumberType)value).Value();
}
else if (value.GetType() == TypeFloat)
{
newValue = newValuef = ((FloatType)value).Value();
}
else if(value.GetType() == TypeString)
{
if (property.Value() == "temp")
{
std::string newString = ((StringType)value).Value();
if (newString.at(newString.length()-1) == 'C')
newValuef = atof(newString.substr(0, newString.length()-1).c_str())+273.15;
else if (newString.at(newString.length()-1) == 'F')
newValuef = (atof(newString.substr(0, newString.length()-1).c_str())-32.0f)*5/9+273.15f;
else
throw GeneralException("Invalid value for assignment");
}
else
{
newValue = GetParticleType(((StringType)value).Value());
if (newValue < 0 || newValue >= PT_NUM)
{
// TODO: add element CAKE to invalidate this
if (!strcasecmp(((StringType)value).Value().c_str(),"cake"))
throw GeneralException("Cake is a lie, not an element");
throw GeneralException("Invalid element");
}
}
}
else
throw GeneralException("Invalid value for assignment");
if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM || !sim->elements[newValue].Enabled))
throw GeneralException("Invalid element");
if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
{
int partIndex = -1;
if(selector.GetType() == TypePoint)
{
ui::Point tempPoint = ((PointType)selector).Value();
if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
throw GeneralException("Invalid position");
}
else
partIndex = ((NumberType)selector).Value();
if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0)
throw GeneralException("Invalid particle");
switch(propertyFormat)
{
case FormatInt:
*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
break;
case FormatFloat:
*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValuef;
break;
}
returnValue = 1;
}
else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all")
{
switch(propertyFormat)
{
case FormatInt:
{
for(int j = 0; j < NPART; j++)
if(sim->parts[j].type)
{
returnValue++;
*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
}
}
break;
case FormatFloat:
{
//.........这里部分代码省略.........
示例4: tptS_set
AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
//Arguments from stack
StringType property = eval(words);
AnyType selector = eval(words);
AnyType value = eval(words);
Simulation * sim = m->GetSimulation();
unsigned char * partsBlock = (unsigned char*)&sim->parts[0];
int returnValue = 0;
FormatType propertyFormat;
int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat);
if(propertyOffset==-1)
throw GeneralException("Invalid property");
//Selector
int newValue;
if(value.GetType() == TypeNumber)
newValue = ((NumberType)value).Value();
else if(value.GetType() == TypeString)
{
newValue = GetParticleType(((StringType)value).Value());
if (newValue < 0 || newValue >= PT_NUM)
throw GeneralException("Invalid element");
}
else
throw GeneralException("Invalid value for assignment");
if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM))
throw GeneralException("Invalid element");
if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
{
int partIndex = -1;
if(selector.GetType() == TypePoint)
{
ui::Point tempPoint = ((PointType)selector).Value();
if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
throw GeneralException("Invalid position");
}
else
partIndex = ((NumberType)selector).Value();
if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0)
throw GeneralException("Invalid particle");
switch(propertyFormat)
{
case FormatInt:
*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
break;
case FormatFloat:
*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
break;
}
returnValue = 1;
}
else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all")
{
switch(propertyFormat)
{
case FormatInt:
{
for(int j = 0; j < NPART; j++)
if(sim->parts[j].type)
{
returnValue++;
*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
}
}
break;
case FormatFloat:
{
for(int j = 0; j < NPART; j++)
if(sim->parts[j].type)
{
returnValue++;
*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
}
}
break;
}
}
else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber)
{
int type;
if(selector.GetType() == TypeNumber)
type = ((NumberType)selector).Value();
else if(selector.GetType() == TypeString)
type = GetParticleType(((StringType)selector).Value());
if(type<0 || type>=PT_NUM)
throw GeneralException("Invalid particle type");
std::cout << propertyOffset << std::endl;
switch(propertyFormat)
{
case FormatInt:
{
//.........这里部分代码省略.........