Logo Search packages:      
Sourcecode: libqalculate version File versions  Download package

bool Calculator::nameTaken ( string  name,
ExpressionItem object = NULL 
)

Checks if a name is used by another object which is not allowed to have the same name.

Parameters:
name Name.
object Object to exclude from check.
Returns:
true if the name is used.

Definition at line 3197 of file Calculator.cc.

References ExpressionItem::type(), TYPE_FUNCTION, TYPE_UNIT, and TYPE_VARIABLE.

                                                              {
      if(name.empty()) return false;
      if(object) {
            switch(object->type()) {
                  case TYPE_VARIABLE: {}
                  case TYPE_UNIT: {
                        for(size_t index = 0; index < variables.size(); index++) {
                              if(variables[index]->isActive() && variables[index]->hasName(name)) {
                                    return variables[index] != object;
                              }
                        }
                        for(size_t i = 0; i < units.size(); i++) {
                              if(units[i]->isActive() && units[i]->hasName(name)) {
                                    return units[i] != object;
                              }
                        }
                        break;
                  }
                  case TYPE_FUNCTION: {
                        for(size_t index = 0; index < functions.size(); index++) {
                              if(functions[index]->isActive() && functions[index]->hasName(name)) {
                                    return functions[index] != object;
                              }
                        }
                        break;
                  }
            }
      } else {
            return getActiveExpressionItem(name) != NULL;
      }
      return false;
}


Generated by  Doxygen 1.6.0   Back to index