本文整理汇总了C++中Map::Find方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::Find方法的具体用法?C++ Map::Find怎么用?C++ Map::Find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map::Find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetSelection
MapIndex* GetSelection() const
{
MapIndex*const* map = m_maps.Find(m_currentlySelectedId);
if(map)
return *map;
return nullptr;
}
示例2: GetSelectedDifficulty
DifficultyIndex* GetSelectedDifficulty() const
{
MapIndex*const* map = m_maps.Find(m_currentlySelectedId);
if(map)
{
return map[0]->difficulties[m_currentlySelectedDiff];
}
return nullptr;
}
示例3: SelectDifficulty
void SelectDifficulty(int32 newDiff)
{
m_currentSelection->SetSelectedDifficulty(newDiff);
m_currentlySelectedDiff = newDiff;
MapIndex** map = m_maps.Find(m_currentlySelectedId);
if(map)
{
OnDifficultySelected.Call(map[0]->difficulties[m_currentlySelectedDiff]);
}
}
示例4: writeToFile
//*******************************************************//
// Read in the expression and process it and write it
// to the file pointed by f_output.
// 1. Parameters should be replaced by its value. If the
// value is less than 0, the value should be wrapped
// by '( )'.
// 2. States such as x.delta should be replaced by its index
// such as x_0.
// 3. Math symbols (+-*/()<>=) should be write to the file
// directly and add space before and after it.
// 4. Variables that are not defined as parameters are write
// directly into the file.
// 5. expression should not include the ';' at the end
// Return nothing.
//*******************************************************//
void writeToFile(FILE *f_output, char *expression,
Map param_map, char inputs[10][20], char states[10][20], char measures[10][20],
int inputs_num, int states_num, int measures_num,
char *x_old, char *x_new, char *u, char *ubar, char *weight, char *y)
{
int len = strlen(expression);
int temp_len;
int isFound;
int index;
char *ptr = expression;
char *temp_ptr = (char*)malloc(len+1);
char *temp_ptr2 = (char*)malloc(len+1);
char *token;
double value;
char *major, *minor;
while(ptr != expression + len){
// Current token is a whitespace, skip it
if (*ptr == ' ' || *ptr == '\t' || *ptr == '.') ptr ++;
// I. Current postion is '<' or '>', check if there is an '=' following
else if(*ptr == '>' || *ptr == '<'){
fprintf(f_output, "%c", *ptr);
ptr ++;
if(*ptr == '='){
fprintf(f_output, "= ");
ptr ++;
}
else
fprintf(f_output, " ");
}
// II. Current postion is a math symbol
else if(isMathSymbol(ptr)){
fprintf(f_output, "%c ", *ptr);
ptr ++;
}
// III. Current position is a digit, write the number to the file directly
else if(isDigit(ptr)){
strcpy(temp_ptr, ptr);
token = strtok(temp_ptr, " ,+-*/()<>=\r\n\t"); // Get the string which represents a number
// Dealing with situations like 1.0e-10
if (token[strlen(token)-1] == 'e'){
temp_len = strlen(token);
ptr += temp_len; // *ptr should be '+' or '-'
if(*ptr == '+' || *ptr == '-'){
token[temp_len] = *ptr;
token[temp_len +1] = '\0';
ptr ++;
}
strcpy(temp_ptr2, ptr);
strcat(token, strtok(temp_ptr2, " ,+-*/()=\r\n\t"));
ptr += strlen(token) - temp_len - 1;
}
else
ptr += strlen(token);
fprintf(f_output, "%s ", token);
}
// IV. Current token is a variable or sqrt or exp or pow
// 1. Parameter
// 2. New variable
// 3. Control signal or state variables
// 4. Random number
// 5. sqrt
else if(isLetter(ptr)){
strcpy(temp_ptr, ptr);
token = strtok(temp_ptr, " ,+-*/()\r\n\t"); // Get the string which represents a variable's name
ptr += strlen(token);
value = param_map.Find(token, &isFound);
// The variable is a defined parameter
if(isFound == 1){
if(value < 0.0)
fprintf(f_output, "(%lf) ", value);
else
fprintf(f_output, "%lf ", value);
}
// The variable is randn(1)
else if(strcmp(token, "randn") == 0){
fprintf(f_output, "RANDN ");
ptr += 3; // skip (1)
}
// The variable is sqrt or exp
else if(strcmp(token, "sqrt") == 0 || strcmp(token, "exp") == 0 || strcmp(token, "pow") == 0)
fprintf(f_output, "%s", token);
//.........这里部分代码省略.........
示例5: evaluate
//*******************************************************//
// Evaluate the value of expression.
// 1. If a double occurs, push it into the value stack
// 2. If a parameter occurs, find its value in param_map
// and push its value in the value stack.
// 3. If an operator occurs, push it into the op stack
// or do some calculations according to the predecence
// of the operator and the op on top of the stack
// 4. If a '(' or ')' occurs, push it into the op stack
// or do some calculations.
// Return the value of the expression
//*******************************************************//
double evaluate(Map param_map, char* expression)
{
Stack<double> values_stack;
Stack<char> ops_stack;
char *ptr = expression;
char *token;
double value, val1, val2;
int len = strlen(expression); // length of the expression
int temp_len;
int isFound;
char *temp_ptr = (char*)malloc(len+1);
char *temp_ptr2 = (char*)malloc(len+1);
// If the expression starts with a '-', add 0.0 in front of the expression
if(*ptr == '-'){
values_stack.Push(0.0);
ops_stack.Push('-');
ptr ++;
}
while(ptr != expression + len){
// Current token is a whitespace, skip it
if(*ptr == ' ') ptr ++;
// I. Current token is a number, push it to stack for numbers
else if(isDigit(ptr)){
strcpy(temp_ptr, ptr);
token = strtok(temp_ptr, " +-*/()\r\n\t"); // Get the string which represents a number
// Dealing with situations like 1.0e-10
if (token[strlen(token)-1] == 'e'){
temp_len = strlen(token);
ptr += temp_len; // *ptr should be '+' or '-'
if(*ptr == '+' || *ptr == '-'){
token[temp_len] = *ptr;
token[temp_len +1] = '\0';
ptr ++;
}
strcpy(temp_ptr2, ptr);
strcat(token, strtok(temp_ptr2, " +-*/()\r\n\t"));
ptr += strlen(token) - temp_len - 1;
}
else
ptr += strlen(token);
values_stack.Push(strtod(token,NULL));
}
// II. Current token is a variable, check if it is defined.
// If so, push it to stack for numbers
else if(isLetter(ptr)){
strcpy(temp_ptr, ptr);
token = strtok(temp_ptr, " +-*/()\r\n\t"); // Get the string which represents a variable's name
ptr += strlen(token);
value = param_map.Find(token, &isFound);
if(isFound == 0){ // The parameter is not defined yet
cout<<"Undefined parameter : "<<token<<endl;
exit(1);
}
values_stack.Push(value);
}
// III. Current token is an opening brace, push it to 'ops'
else if(*ptr == '('){
ops_stack.Push(*ptr);
ptr ++;
}
// IV. Closing brace encountered, solve entire brace
else if(*ptr == ')'){
while(ops_stack.Peek(0) != '(')
values_stack.Push(applyOp(ops_stack.Pop(), values_stack.Pop(), values_stack.Pop()));
ops_stack.Pop();
ptr ++;
}
// V. Current token is an operator.
else if (isOperator(ptr))
{
// While top of 'ops' has same or greater precedence to current
// token, which is an operator. Apply operator on top of 'ops'
// to top two elements in values stack
while (!ops_stack.Empty() && hasPrecedence(*ptr, ops_stack.Peek(0))){
val1 = values_stack.Pop();
val2 = values_stack.Pop();
values_stack.Push(applyOp(ops_stack.Pop(), val1, val2));
}
// Push current token to 'ops'.
ops_stack.Push(*ptr);
ptr ++;
}
}
//.........这里部分代码省略.........