Exemplo n.º 1
0
LineParser &LineParser::parse( int argn, char *const *argv )
{
  int             val, arg, diff;
  Mixed           optional;
  const option_s *begin = &(*this->lp_data.pd_options.begin());

  while( (val = getopt_long(argn, argv, this->lp_data.pd_optstring.c_str(), begin, NULL)) != EOF ) {
    if( val == 'h' ) {
      this->lp_data.pd_progname.assign( argv[0] );
      throw ShowHelp( this->lp_data );
    }
    else if( val == '?' ) {
      this->lp_data.pd_progname.assign( argv[0] );
      throw InvalidOption( this->lp_data, optopt );
    }
    else if( this->lp_data.pd_argmap.count(val) != 0 ) {
      switch( this->lp_data.pd_argmap[val] ) {
      case no_argument:
	this->lp_map.insert( map<char, Mixed>::value_type((char) val, Mixed(true)) );
	break;
      case required_argument:
	this->lp_map.insert( map<char, Mixed>::value_type((char) val, Mixed(optarg)) );
	break;
      case optional_argument:
      default:
	if( optarg == NULL ) {
	  if( (optind < argn) && (argv[optind][0] != '-') ) {
	    optional.setStringValue( argv[optind] );
	    optind += 1;
	  }
	  else optional.setLogicalValue( true );
	}
	else optional.setStringValue( optarg );

	this->lp_map.insert( map<char, Mixed>::value_type((char) val, optional) );
	break;
      }
    }
  }

  diff = argn - optind;
  if( (((this->lp_data.pd_paramnumber == (int) ParserData::one_or_more) && (diff > 0)) ||
       ((this->lp_data.pd_paramnumber == (int) ParserData::zero_or_more) && (diff >= 0)) ||
       ((this->lp_data.pd_paramnumber >= 0) && (diff == this->lp_data.pd_paramnumber))) ) {
    for( arg = optind; arg < argn; arg++ )
      this->lp_arguments.push_back( argv[arg] );
  }
  else {
    this->lp_data.pd_progname.assign( argv[0] );
    throw InvalidArgNumber( this->lp_data, diff );
  }

  return *this;
}
template<> Timestamp get(Mixed m) { return m.get_timestamp(); }
template<> double get(Mixed m) { return m.get_double(); }
template<> float get(Mixed m) { return m.get_type() == type_Float ? m.get_float() : static_cast<float>(m.get_double()); }
template<> int64_t get(Mixed m) { return m.get_int(); }
Exemplo n.º 6
0
Mixed Mixed::operator /(Mixed &p){
		p.ToFraction();
		Mixed tmp(0, b*p.c,c*p.b);
		tmp.Simplify();
		return tmp;
}
Exemplo n.º 7
0
Mixed Mixed::operator -(Mixed &p){
		p.ToFraction();
		Mixed tmp(0, (b*p.c) - (p.b*c),c*p.c);
		tmp.Simplify();
}
Exemplo n.º 8
0
Mixed Mixed::operator +(Mixed &p){
		p.ToFraction();
		Mixed tmp(0, (b*p.c) + (p.b*c),c*p.c);
		tmp.Simplify();
		return tmp;
}
Exemplo n.º 9
0
bool Mixed::operator !=(Mixed &p){
		p.ToFraction();
		int y = p.get_y(), z = p.get_z();
		return ((((b*z) != (y*c)))?1:0);
}
Exemplo n.º 10
0
jobject CreateJMixedFromMixed(JNIEnv* env, Mixed& mixed)
{
    jclass jMixedClass = GetClassMixed(env);
    if (jMixedClass == NULL)
        return NULL;

    TR((env, "CreateJMixedFromMixed(type %d)\n", mixed.get_type()));
    switch (mixed.get_type()) {
    case type_Int:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(J)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_int());
    }
    case type_Float:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(F)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_float());
    }
    case type_Double:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(D)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_double());
    }
    case type_String:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/lang/String;)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, to_jstring(env, mixed.get_string()));
    }
    case type_Bool:
    {
        jmethodID consId = GetMixedMethodID(env, "<init>", "(Z)V");
        if (consId)
            return env->NewObject(jMixedClass, consId, mixed.get_bool());
    }
    case type_DateTime:
        {
            time_t timeValue = mixed.get_datetime().get_datetime();
            jclass jDateClass = env->FindClass("java/util/Date");
            if (jDateClass == NULL) {
                ThrowException(env, ClassNotFound, "Date");
                return NULL;
            }
            jmethodID jDateConsId = env->GetMethodID(jDateClass, "<init>", "(J)V");
            if (jDateConsId == NULL) {
                ThrowException(env, NoSuchMethod, "Date", "<init>");
                return NULL;
            }
            jobject jDate = env->NewObject(jDateClass, jDateConsId, static_cast<jlong>(timeValue));
            jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/util/Date;)V");
            if (consId)
                return env->NewObject(jMixedClass, consId, jDate);
        }
    case type_Binary:
        {
            BinaryData binaryData = mixed.get_binary();
            jmethodID consId = GetMixedMethodID(env, "<init>", "(Ljava/nio/ByteBuffer;)V");
            if (consId) {
                jobject jByteBuffer = env->NewDirectByteBuffer(const_cast<char*>(binaryData.data()), binaryData.size());
                return env->NewObject(jMixedClass, consId, jByteBuffer);
            }
        }
    case type_Table:
        {
            // param input: Table* t.
            TR((env, "   --Mixed(type_Table)\n"));
            jmethodID consId = GetMixedMethodID(env, "<init>", "(Lio/realm/internal/ColumnType;)V");

            jobject jColumnType = NULL; // GetJColumnTypeFromColumnType(env, type_Table);
            if (consId)
                return env->NewObject(jMixedClass, consId, jColumnType);
        }
    case type_Mixed:
        break;
    case type_Link:
        break;
    case type_LinkList:
        break;
    }

    return NULL;
}