<commit_before>// Filename: IntValue.cpp
#include "IntValue.h"
#include <limits>    // numeric_limits
#include <stdexcept> // invalid_argument
#include <typeinfo>  // bad_cast
#include "../bits/buffers.h"
#include "../module/DistributedType.h"
using namespace std;
namespace bamboo {


template<typename T>
static inline bool within_limits(int64_t num) {
    return numeric_limits<T>::min() <= num && num <= numeric_limits<T>::max();
}
template<typename T>
static inline bool within_limits(uint64_t num) {
    return num <= numeric_limits<T>::max();
}

IntValue::IntValue() { m_unsigned = 0; }
IntValue::IntValue(int8_t num) { m_signed = num; }
IntValue::IntValue(uint8_t num) { m_unsigned = num; }
IntValue::IntValue(int16_t num) { m_signed = num; }
IntValue::IntValue(uint16_t num) { m_unsigned = num; }
IntValue::IntValue(int32_t num) { m_signed = num; }
IntValue::IntValue(uint32_t num) { m_unsigned = num; }
IntValue::IntValue(int64_t num) { m_signed = num; }
IntValue::IntValue(uint64_t num) { m_unsigned = num; }

// pack provides the packed data for the value in native endianness.
//     Throws: bad_cast
vector<uint8_t> IntValue::pack(const DistributedType *type) const {
    if(type->get_subtype() > kTypeChar) {
        throw invalid_argument("can't pack integer value as non-integer type.");
    }

    switch(type->get_size()) {
        case sizeof(uint8_t):
            return as_buffer(uint8_t(m_unsigned));
        case sizeof(uint16_t):
            return as_buffer(uint16_t(m_unsigned));
        case sizeof(uint32_t):
            return as_buffer(uint32_t(m_unsigned));
        case sizeof(uint64_t):
            return as_buffer(uint64_t(m_unsigned));
        default:
            throw invalid_argument("integer type has an invalid bytesize.");
    }
}
void IntValue::pack(const DistributedType *type, vector<uint8_t>& buf) const {
    if(type->get_subtype() > kTypeChar) {
        throw invalid_argument("can't pack integer value as non-integer type.");
    }

    switch(type->get_size()) {
        case sizeof(uint8_t):
            pack_value(uint8_t(m_unsigned), buf);
        case sizeof(uint16_t):
            pack_value(uint16_t(m_unsigned), buf);
        case sizeof(uint32_t):
            pack_value(uint32_t(m_unsigned), buf);
        case sizeof(uint64_t):
            pack_value(uint64_t(m_unsigned), buf);
        default:
            throw invalid_argument("integer type has an invalid bytesize.");
    }
}

char IntValue::as_char() const {
    if(!within_limits<char>(m_signed)) { throw bad_cast(); }
    return m_signed;<commit_msg>Bugfix: Add missing break statements in IntValue.cpp<commit_after>// Filename: IntValue.cpp
#include "IntValue.h"
#include <limits>    // numeric_limits
#include <stdexcept> // invalid_argument
#include <typeinfo>  // bad_cast
#include "../bits/buffers.h"
#include "../module/DistributedType.h"
using namespace std;
namespace bamboo {


template<typename T>
static inline bool within_limits(int64_t num) {
    return numeric_limits<T>::min() <= num && num <= numeric_limits<T>::max();
}
template<typename T>
static inline bool within_limits(uint64_t num) {
    return num <= numeric_limits<T>::max();
}

IntValue::IntValue() { m_unsigned = 0; }
IntValue::IntValue(int8_t num) { m_signed = num; }
IntValue::IntValue(uint8_t num) { m_unsigned = num; }
IntValue::IntValue(int16_t num) { m_signed = num; }
IntValue::IntValue(uint16_t num) { m_unsigned = num; }
IntValue::IntValue(int32_t num) { m_signed = num; }
IntValue::IntValue(uint32_t num) { m_unsigned = num; }
IntValue::IntValue(int64_t num) { m_signed = num; }
IntValue::IntValue(uint64_t num) { m_unsigned = num; }

// pack provides the packed data for the value in native endianness.
//     Throws: bad_cast
vector<uint8_t> IntValue::pack(const DistributedType *type) const {
    if(type->get_subtype() > kTypeChar) {
        throw invalid_argument("can't pack integer value as non-integer type.");
    }

    switch(type->get_size()) {
        case sizeof(uint8_t):
            return as_buffer(uint8_t(m_unsigned));
        case sizeof(uint16_t):
            return as_buffer(uint16_t(m_unsigned));
        case sizeof(uint32_t):
            return as_buffer(uint32_t(m_unsigned));
        case sizeof(uint64_t):
            return as_buffer(uint64_t(m_unsigned));
        default:
            throw invalid_argument("integer type has an invalid bytesize.");
    }
}
void IntValue::pack(const DistributedType *type, vector<uint8_t>& buf) const {
    if(type->get_subtype() > kTypeChar) {
        throw invalid_argument("can't pack integer value as non-integer type.");
    }

    switch(type->get_size()) {
        case sizeof(uint8_t):
            pack_value(uint8_t(m_unsigned), buf);
            break;
        case sizeof(uint16_t):
            pack_value(uint16_t(m_unsigned), buf);
            break;
        case sizeof(uint32_t):
            pack_value(uint32_t(m_unsigned), buf);
            break;
        case sizeof(uint64_t):
            pack_value(uint64_t(m_unsigned), buf);
            break;
        default:
            throw invalid_argument("integer type has an invalid bytesize.");
    }
}

char IntValue::as_char() const {
    if(!within_limits<char>(m_signed)) { throw bad_cast(); }
    return m_signed;
{'fraction_non_alphanumeric': 0.12749762131303521, 'fraction_numerical': 0.018648905803996193, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '736776', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1684, 'n_words': 375}