Exemple #1
0
 /*static*/ integer_type f_to_i(const floating_type& f)
 {
     std::string str = f.str(0, std::ios_base::fixed);
     size_t i = str.find('.');
     if (i != std::string::npos)
         str = str.substr(0, i);
     return integer_type(str);
 }
VerificationType VerificationType::from_tag(u1 tag) {
  switch (tag) {
    case ITEM_Top:     return bogus_type();
    case ITEM_Integer: return integer_type();
    case ITEM_Float:   return float_type();
    case ITEM_Double:  return double_type();
    case ITEM_Long:    return long_type();
    case ITEM_Null:    return null_type();
    default:
      ShouldNotReachHere();
      return bogus_type();
  }
}
Exemple #3
0
    /*static*/ rational_type f_to_r(const floating_type& f)
    {
        integer_type n = f_to_i(f);
        floating_type m = f - i_to_f(n);
        if (m.is_zero())
            return rational_type(n, integer_type(1));

        integer_type k("620448401733239439360000"); // 24!
        m *= floating_type(k);
        integer_type j = f_to_i(m + 0.5);
        j += n * k + 1;
        return rational_type(j, k);
    }
 /// \effects Decrements the integer by one.
 /// \group decrement
 TYPE_SAFE_FORCE_INLINE integer& operator--()
 {
     value_ = Policy::template do_subtraction(value_, integer_type(1));
     return *this;
 }
Exemple #5
0
ERROR_CODE _bencoding_integer_end_callback(struct bencoding_engine_t *bencoding_engine, const unsigned char *pointer, size_t size) {
    /* allocates space for the integer value and for
    the type that will encapsulate it */
    int _integer;
    struct type_t *type;

    /* retrieves the bencoding handler from the template engine context
    then uses it to store the (current) value */
    struct bencoding_handler_t *bencoding_handler = (struct bencoding_handler_t *) bencoding_engine->context;

    /* allocates space for the integer string value and then copies
    the data buffer into it and terminates the null string */
    char *integer = MALLOC(size + 1);
    memcpy(integer, pointer, size);
    integer[size] = '\0';

    /* in case the sequence type is defined the integer must
    be a value and must be associated with the sequence */
    if(bencoding_handler->sequence != NULL) {
        /* converts the integer string into an integer value, then creates
        the type structure for the integer and sets it as an integer value */
        _integer = atoi(integer);
        create_type(&type, INTEGER_TYPE);
        *type = integer_type(_integer);

        /* switches over the type of current sequence to
        execute the proper operations */
        switch(bencoding_handler->sequence->type) {
            case LIST_TYPE:
                /* adds the current type to the list sequence */
                append_value_linked_list(bencoding_handler->sequence->value.value_list, (void *) type);

                /* breaks the switch */
                break;

            case MAP_TYPE:
                /* sets the value in the map for the current key and sets the next key
                flag so that the next string is saved as a key */
                set_value_string_hash_map(bencoding_handler->sequence->value.value_map, bencoding_handler->key, (void *) type);
                bencoding_handler->next_key = 1;

                /* breaks the switch */
                break;

            case SORT_MAP_TYPE:
                /* sets the value in the map for the current key and sets the next key
                flag so that the next string is saved as a key */
                set_value_string_sort_map(bencoding_handler->sequence->value.value_sort_map, bencoding_handler->key, (void *) type);
                bencoding_handler->next_key = 1;

                /* breaks the switch */
                break;

            default:
                /* breaks the switch */
                break;
        }
    }

    /* in case there is no top type defined for the handler sets the
    current type as the top type (base type) */
    if(bencoding_handler->top == NULL) { bencoding_handler->top = type; }

    /* releases the memory associated with the intger string value
    in order to avoid memory leaks */
    FREE(integer);

    /* raises no error */
    RAISE_NO_ERROR;
}