bool isNumeric(char* string)
    {
        int sz = strlen(string);
        if (sz == 0) return false;
        int fi=0;
        char *s = string;
        bool dot = false, ep = false;
        if (!isInt(s, fi, sz - 1,dot)) return false;


        for (; fi < sz; fi++){
            if (dot){
                if (!(s[fi] >= '0'&&s[fi] <= '9') && s[fi] != 'e'&&s[fi] != 'E') return false;
            }			
            else{
                if (!(s[fi] >= '0'&&s[fi] <= '9') && s[fi] != 'e'&&s[fi] != 'E' && s[fi] != '.') return false;
            }			
            if (s[fi] == '.') {
                dot = true;
            }
            if (s[fi] == 'e' || s[fi] == 'E') {
                ep = true; break;
            }
        }
        dot = false;
        if (ep) {
            fi++;
            if(!isInt(s, fi, sz - 1,dot)) return false;
            if (dot == true) return false;
            for (; fi <sz ; fi++){
                if (!(s[fi] >= '0'&&s[fi] <= '9')) return false;
            }
        }
        return true;
    }
Example #2
0
Optional<Opcode> invertedCompare(Opcode opcode, Type type)
{
    switch (opcode) {
    case Equal:
        return NotEqual;
    case NotEqual:
        return Equal;
    case LessThan:
        if (isInt(type))
            return GreaterEqual;
        return Nullopt;
    case GreaterThan:
        if (isInt(type))
            return LessEqual;
        return Nullopt;
    case LessEqual:
        if (isInt(type))
            return GreaterThan;
        return Nullopt;
    case GreaterEqual:
        if (isInt(type))
            return LessThan;
        return Nullopt;
    case Above:
        return BelowEqual;
    case Below:
        return AboveEqual;
    case AboveEqual:
        return Below;
    case BelowEqual:
        return Above;
    default:
        return Nullopt;
    }
}
Example #3
0
//ONLY USED IF USING DESCRIPTORS
SpriteSheetDescription Resources::loadDescription(std::string fileName) {
    std::string filePath = TEXTURETPATH + fileName + TEXTUREDESCRIPTIONEXTENSION;
    SpriteSheetDescription ret;
    // leer el fichero
    std::ifstream file(filePath);
    if (!file.is_open()) {
        std::cout << "Error opening file on resources loadDescription " << filePath << std::endl;
        exit(EXIT_FAILURE);
    }
    std::vector<std::pair<int, std::string> > v;
    int lineNum = 0;
    std::string line;
    while (getline(file,line)) {
        ++lineNum;
        for (int i = 0; i < int(line.size()-1); ++i) {
            if (line[i] == '/' && line[i+1] == '/') {
                line = line.substr(0,i);
                break;
            }
        }
        std::istringstream aux(line);
        std::string s;
        while(aux >> s) 
            v.push_back(std::make_pair(lineNum,s));
    }
    SpriteSheetDescription ssd;
    std::map<std::string, int> positions;
    for (int  i = 0; i < int(v.size()); ++i) {
        lineNum = v[i].first;
        std::string key = v[i].second;
        int descriptorPosition;
        if (positions.find(key) == positions.end()) {
            descriptorPosition = positions.size();
            positions.insert(std::make_pair(key,descriptorPosition));
            ssd.push_back(std::vector<sf::IntRect>());
        }
        else {
            descriptorPosition = positions[key];
        }
        //std::cout << "insertando la key " << key << " en la posicion " << descriptorPosition << std::endl;

        if (i+4 >= int(v.size()) || 
            !isInt(v[i+1].second) || 
            !isInt(v[i+2].second) || 
            !isInt(v[i+3].second) || 
            !isInt(v[i+4].second)) {
            std::cout << "Error in line " << lineNum << ": four integers are needed" << std::endl;
            exit(EXIT_FAILURE);
        }
        sf::IntRect intRect(myStoi(v[i+1].second),
            myStoi(v[i+2].second),
            myStoi(v[i+3].second),
            myStoi(v[i+4].second));
        ssd[descriptorPosition].push_back(intRect);
        i += 4;
    }

    return ssd;
}
Example #4
0
int input(int argLen, char* zinomoton[], int* customers, int* numOfTellers, float* simTime, float* avgService)
{
	if (argLen>6)
	{
		printf("I'm sorry, you've entered too many arguments.\n");
		return EXIT_FAILURE;
	}
	if (argLen<5)
	{
		printf("I'm sorry, you've entered too few arguments.\n");
		return EXIT_FAILURE;
	}
	if (isInt(zinomoton[1],FALSE)) *customers = atoi(zinomoton[1]);
	else
	{
		printf("I'm sorry, but the number of customers (the first parameter) must be a positive integer.\n");
		return EXIT_FAILURE;
	}
	if (isInt(zinomoton[2],FALSE)) *numOfTellers = atoi(zinomoton[2]);
	else
	{
		printf("I'm sorry, but the number of tellers (the second parameter) must be a positive integer.\n");
		return EXIT_FAILURE;
	}
	if (isDec(zinomoton[3],FALSE)) *simTime = atof(zinomoton[3]);
	else
	{
		printf("I'm sorry, but the simulation time (the third parameter) must be a positive real number.\n");
		return EXIT_FAILURE;
	}
	if (isDec(zinomoton[4],FALSE)) *avgService = atof(zinomoton[4]);
	else
	{
		printf("I'm sorry, but the average service time (the fourth parameter) must be a positive real number.\n");
		return EXIT_FAILURE;
	}
	if (argLen==6)
	{
		if (isInt(zinomoton[5],FALSE)) srand(atoi(zinomoton[5]));
		else
		{
			printf("I'm sorry, but the random seed (the fifth parameter) must be a positive integer.\n");
			return EXIT_FAILURE;
		}
	}
	else
	{
		struct timeval time;
		gettimeofday(&time,NULL);
		srand(time.tv_usec);
	}

	return EXIT_SUCCESS;
}
Example #5
0
bool GenericType::can_cast_to(opt_type other) const {
  switch (other) {
      case OT_BOOLEAN:
        return isBool() || isInt() || isDouble();
      case OT_BOOLVECTOR:
        return isIntVector() || isDoubleVector();
      case OT_INTEGER: case OT_REAL:
        return isInt() || isDouble();
      case OT_INTEGERVECTOR: case OT_REALVECTOR:
        return isDoubleVector() || isIntVector();
      default:
        return type_ == other;
  }
}
Example #6
0
bool dynamic::operator==(dynamic const& o) const {
  if (type() != o.type()) {
    if (isNumber() && o.isNumber()) {
      auto& integ = isInt() ? *this : o;
      auto& doubl = isInt() ? o     : *this;
      return integ.asInt() == doubl.asDouble();
    }
    return false;
  }

#define FB_X(T) return *getAddress<T>() == *o.getAddress<T>();
  FB_DYNAMIC_APPLY(type_, FB_X);
#undef FB_X
}
Example #7
0
  int Lisp::eval(){
    switch(buf[index]){
    case '(':
      ++depth;
    case ' ':
    case '\t':
      ++index;
      return eval();
    case ')':
      --depth;
      ++index;
      return 0; //eval()を続けないという意味であり、0に意味があるわけではない。
    case '+':
      ++index;
      return plus();
    case '-':
      ++index;
      return sub();
    case '*':
      ++index;
      return mul();
    case '/':
      ++index;
      return div();
    default:
      break;
    }

    if(isInt(buf.substr(index,1))){
      return stoi(lexInt());
    }else{
      cout << "Error" << endl;
      return 0;
    }
  }
Example #8
0
/** reads the nblocks section */
static
SCIP_RETCODE readNBlocks(
    SCIP*                 scip,               /**< SCIP data structure */
    BLKINPUT*             blkinput            /**< BLK reading data */
)
{
    int nblocks;

    assert(scip != NULL);
    assert(blkinput != NULL);

    while( getNextToken(blkinput) )
    {
        /* check if we reached a new section */
        if( isNewSection(scip, blkinput) )
        {
            if( blkinput->nblocks == NOVALUE )
                syntaxError(scip, blkinput, "no integer value in nblocks section");
            else
                return SCIP_OKAY;
        }

        /* read number of blocks */
        if( isInt(scip, blkinput, &nblocks) )
        {
            if( blkinput->nblocks == NOVALUE )
                blkinput->nblocks = nblocks;
            else
                syntaxError(scip, blkinput, "2 integer values in nblocks section");
            SCIPdebugMessage("Number of blocks = %d\n", blkinput->nblocks);
        }
    }

    return SCIP_OKAY;
}
Example #9
0
/** reads the presolved section */
static
SCIP_RETCODE readPresolved(
    SCIP*                 scip,               /**< SCIP data structure */
    BLKINPUT*             blkinput            /**< DEC reading data */
)
{
    int presolved;

    assert(scip != NULL);
    assert(blkinput != NULL);

    while( getNextToken(blkinput) )
    {
        /* check if we reached a new section */
        if( isNewSection(scip, blkinput) )
            return SCIP_OKAY;

        /* read number of blocks */
        if( isInt(scip, blkinput, &presolved) )
        {
            blkinput->haspresolvesection = TRUE;
            if( presolved == 1 )
                blkinput->presolved = TRUE;
            else if ( presolved == 0 )
                blkinput->presolved = FALSE;
            else
                syntaxError(scip, blkinput, "presolved parameter must be 0 or 1");
            SCIPdebugMessage("Decomposition is%s from presolved problem\n",
                             blkinput->presolved ? "" : " not");
        }
    }

    return SCIP_OKAY;
}
Example #10
0
inline int64 DictValue::get<int64>(int idx) const
{
    CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
    idx = (idx == -1) ? 0 : idx;

    if (type == Param::INT)
    {
        return (*pi)[idx];
    }
    else if (type == Param::REAL)
    {
        double doubleValue = (*pd)[idx];

        double fracpart, intpart;
        fracpart = std::modf(doubleValue, &intpart);
        CV_Assert(fracpart == 0.0);

        return (int64)doubleValue;
    }
    else
    {
        CV_Assert(isInt() || isReal());
        return 0;
    }
}
Example #11
0
    bool isNumber(const char *s) {
        int e = -1;
        while (*s == ' ') s++;
        if (*s == '+' || *s == '-'){
            s++;
        }
        int n = strlen(s);
        while (n>0 && s[n-1] == ' ') n--;

        for (int i = 0; i<n; i++) if (s[i] == 'e'){
            e = i;
        break;
        }
        if (e == -1){
            return isdouble(s, n);
        }
        if (!isdouble(s, e)) return false;
        s += e+1;
        n-=e+1;
        if (*s == '+' || *s == '-'){
            s++;
            n--;
        }
        return isInt(s, n);
    }
Example #12
0
bool Value::isConvertibleTo(ValueType other) const {
  switch (other) {
  case nullValue:
    return (isNumeric() && asDouble() == 0.0) ||
           (type_ == booleanValue && value_.bool_ == false) ||
           (type_ == stringValue && asString() == "") ||
           (type_ == arrayValue && value_.map_->size() == 0) ||
           (type_ == objectValue && value_.map_->size() == 0) ||
           type_ == nullValue;
  case intValue:
    return isInt() ||
           (type_ == realValue && InRange(value_.real_, minInt, maxInt)) ||
           type_ == booleanValue || type_ == nullValue;
  case uintValue:
    return isUInt() ||
           (type_ == realValue && InRange(value_.real_, 0, maxUInt)) ||
           type_ == booleanValue || type_ == nullValue;
  case realValue:
    return isNumeric() || type_ == booleanValue || type_ == nullValue;
  case booleanValue:
    return isNumeric() || type_ == booleanValue || type_ == nullValue;
  case stringValue:
    return isNumeric() || type_ == booleanValue || type_ == stringValue ||
           type_ == nullValue;
  case arrayValue:
    return type_ == arrayValue || type_ == nullValue;
  case objectValue:
    return type_ == objectValue || type_ == nullValue;
  }
  JSON_ASSERT_UNREACHABLE;
  return false;
}
Example #13
0
 Variant getValue(ElmT elm) const {
   if (isInt(elm)) {
     return getInt(elm);
   }
   ASSERT(isStr(elm));
   return getStr(elm);
 }
Example #14
0
 bool isNumber(const char *s) {
     int left = 0, right = strlen(s) - 1;
     while(left <= right && (s[left] == ' ' || s[left] == '\t' || s[left] == '\n')) {
         ++ left;
     }
     while(left <= right && (s[right] == ' ' || s[right] == '\t' || s[right] == '\n')) {
         -- right;
     }
     if (left > right) return false;
     int cnt_dot = 0, cnt_e = 0, pos_e = 0;
     for (int i = left; i <= right; ++i) {
         if (!('0' <= s[i] && s[i] <= '9')) {
             if (s[i] == '.') {
                 ++ cnt_dot;
             } else if (s[i] == 'e' || s[i] == 'E'){
                 ++ cnt_e;
                 pos_e = i;
             } else if (s[i] != '-' && s[i] != '+'){
                 return false;
             }
         }
     }
     if (cnt_e > 1 || cnt_dot > 1) {
         return false;
     }
     if ((cnt_e && isFloat(s, left, pos_e - 1) && isInt(s, pos_e + 1, right)) || (!cnt_e && isFloat(s, left, right))) {
         return true;
     }
     return false;
 }
Example #15
0
void str::operator-=(int n)
{
    if(isInt())
    {
        (*this) = str::toInt(mpStr) - n; // Call Assignment Operator for int
    }
}
Example #16
0
void JsonWrapper::get(const char* name, bool dflt, bool& param) const {
  auto val = m_config.get(name, dflt);

  // Do some simple type conversions that folly used to do
  if (val.isBool()) {
    param = val.asBool();
    return;
  } else if (val.isInt()) {
    auto valInt = val.asInt();
    if (valInt == 0 || valInt == 1) {
      param = (val.asInt() != 0);
      return;
    }
  } else if (val.isString()) {
    auto str = val.asString();
    std::transform(str.begin(), str.end(), str.begin(),
                   [](auto c) { return ::tolower(c); });
    if (str == "0" || str == "false" || str == "off" || str == "no") {
      param = false;
      return;
    } else if (str == "1" || str == "true" || str == "on" || str == "yes") {
      param = true;
      return;
    }
  }
  throw std::runtime_error("Cannot convert JSON value to bool: " +
                           val.asString());
}
Example #17
0
char* handle_expr_single(char* op, ast* a)
{
	if (strcmp(op, "NOT") == 0)
	{
		if (!isBool(a))
		{
			char msg[100];
			strcpy(msg, "expected BOOL but got ");
			strcat(msg, a->type);
			error(msg, a);
			return "TYPE_ERROR";
		}
		return "BOOL";
	}
	else
	{
		if (!isInt(a) && !isReal(a))
		{
			char msg[100];
			strcpy(msg, "expected INTEGER or REAL but got ");
			strcat(msg, a->type);
			error(msg, a);
			return "TYPE_ERROR";
		}
		return a->type;
	}
}
int BSONElement::getInt(void)
{
  int32_t* val = 0;
  if (isInt())
    val = (int32_t*)((char *)&_element + sizeof(char) + strlen(getKey()) + 1);
  return *val;
}
Example #19
0
bool Value::isIntegral() const {
#if defined(JSON_HAS_INT64)
  return isInt64() || isUInt64();
#else
  return isInt() || isUInt();
#endif
}
bool BSONElement::getBool(void)
{
  char* val = 0;
  if (isInt())
    val = (char *)&_element + sizeof(char) + strlen(getKey()) + 1;
  return (*val == 1 ? true : false);
}
Example #21
0
bool GenericType::operator!=(const GenericType& op2) const{
  if(isString() && op2.isString()){
    return toString().compare(op2.toString()) != 0;
  }

  if(isInt() && op2.isInt()){
    return toInt() != op2.toInt();
  }

  if(isDouble() && op2.isDouble()){
    return toDouble() != op2.toDouble();
  }

  if(isDoubleVector() && op2.isDoubleVector()){
    const vector<double> &v1 = toDoubleVector();
    const vector<double> &v2 = op2.toDoubleVector();
    if(v1.size() != v2.size()) return true;
    for(int i=0; i<v1.size(); ++i)
      if(v1[i] != v2[i]) return true;
    return false;
  }

  if(isIntVector() && op2.isIntVector()){
    const vector<int> &v1 = toIntVector();
    const vector<int> &v2 = op2.toIntVector();
    if(v1.size() != v2.size()) return true;
    for(int i=0; i<v1.size(); ++i)
      if(v1[i] != v2[i]) return true;
    return false;
  }
  
  // Different types
  return true;
}
Example #22
0
 Variant getValue(ElmT elm) const {
   if (isInt(elm)) {
     return getInt(elm);
   }
   assert(isStr(elm));
   return getStr(elm);
 }
Example #23
0
//can be 2.-3 which just translates to 2.0-3
int scannar::isDecimal(string data)
{


        size_t point=data.find_first_of(".");
        string regex="0123456789";

        //check for decimal
        if(point!=string::npos)
        {

            size_t numerator = data.substr(0,point).find_first_not_of(regex);
            size_t denominator= data.substr(point+1).find_first_not_of(regex);


           if(numerator!=string::npos||denominator!=string::npos)
           {
               return 2;
           }


        }
        else
        {
            //decimal type can support integers
            if(isInt(data)==1)
            {
                return 1;
            }
            return 2;
        }


    return 1;
}
Example #24
0
double GenericType::toDouble() const{
  if(isInt()){
    return double(toInt());
  } else {
    casadi_assert_message(isDouble(),"type mismatch");
    return static_cast<const DoubleType*>(get())->d_;
  }
}
Example #25
0
Litteral& Rationnel::operator/(const Entier& l) const {
    double tmp = l.getValue()/getValue();
    if (isInt(tmp))
        return LitteralManager::getInstance().addEntier(static_cast<int>(tmp));
    QString s;
    s = QString("%1/%2").arg(getNumerator()).arg(getDenominator()*l.getValue());
    return LitteralManager::getInstance().addRationnel(s);
}
Example #26
0
int main(int argc, char **argv){
	if (argc == 3){
		std::string aString = argv[1];
		std::string bString = argv[2];
		if (isInt(aString) and isInt(bString)){
			int a, b;
			a = toInt(aString);
			b = toInt(bString);
			int answer = gcd(a, b);
			std::cout << "gcd of " << a << " and " << b << " = " << answer << std::endl;
		}
	}
	else{
		std::cout << "It need two integers numbers to work" << std::endl;
	}
	return 0;
}
Example #27
0
void RepoQuery::getInt64(int iCol, int64_t& val) {
  if (!isInt(iCol)) {
    throw RepoExc(
      "RepoQuery::%s(repo=%p) error: Column %d is not an integer in '%s'",
      __func__, &m_stmt.repo(), iCol, m_stmt.sql().c_str());
  }
  val = sqlite3_column_int64(m_stmt.get(), iCol);
}
Example #28
0
int isPt(struct a_NODE *node)
{
	if(!node)
		return FALSE;
	if(node->token == '&')
		return TRUE;
	if(node->token == TK_IDENTIFIER && node->node->type == ID_POINTER)
		return TRUE;

	if(node->token == '+' && isPt(node->sons[0]) && isInt(node->sons[1]))
		return TRUE;
	if(node->token == '+' && isPt(node->sons[1]) && isInt(node->sons[0]))
		return TRUE;
	if(isPt(node->sons[0]))
		return TRUE;
	return FALSE;
}
Example #29
0
A_exp A_NumberExp(A_pos pos, string s)
{A_exp p = checked_malloc(sizeof(*p));
 p->kind=A_numberExp;
 p->pos=pos;
 p->dec_type=isInt(s)?Ty_int:Ty_float;
 p->u.number=s;
 return p;
}
Example #30
0
    bool AsmJsType::isSubType(AsmJsType type) const
    {
        switch (type.which_)
        {
        case Js::AsmJsType::Double:
            return isDouble();
            break;

        case Js::AsmJsType::MaybeDouble:
            return isMaybeDouble();
            break;
        case Js::AsmJsType::DoubleLit:
            return isDoubleLit();
            break;
        case Js::AsmJsType::Float:
            return isFloat();
            break;
        case Js::AsmJsType::MaybeFloat:
            return isMaybeFloat();
            break;
        case Js::AsmJsType::Floatish:
            return isFloatish();
            break;
        case Js::AsmJsType::FloatishDoubleLit:
            return isFloatishDoubleLit();
            break;
        case Js::AsmJsType::Fixnum:
            return which_ == Fixnum;
            break;
        case Js::AsmJsType::Int:
            return isInt();
            break;
        case Js::AsmJsType::Signed:
            return isSigned();
            break;
        case Js::AsmJsType::Unsigned:
            return isUnsigned();
            break;
        case Js::AsmJsType::Intish:
            return isIntish();
            break;
        case Js::AsmJsType::Void:
            return isVoid();
            break;
        case AsmJsType::Int32x4:
            return isSIMDInt32x4();
            break;
        case AsmJsType::Float32x4:
            return isSIMDFloat32x4();
            break;
        case AsmJsType::Float64x2:
            return isSIMDFloat64x2();
            break;
        default:
            break;
        }
        return false;
    }