<commit_before>/*
 * RawStorage.cpp
 *
 * Copyright (C) 2006 by Universitaet Stuttgart (VIS). Alle Rechte vorbehalten.
 */


#include "vislib/RawStorage.h"

#include <stdexcept>

#include "vislib/assert.h"
#include "vislib/memutils.h"
#include "vislib/Trace.h"


/*
 * vislib::RawStorage::RawStorage
 */
vislib::RawStorage::RawStorage(const SIZE_T size) : data(NULL), size(size) {
    this->EnforceSize(this->size);
}


/*
 * vislib::RawStorage::RawStorage
 */
vislib::RawStorage::RawStorage(const RawStorage& rhs) 
        : data(NULL), size(rhs.size) {
    if (this->size > 0) {
        this->EnforceSize(this->size);
        ::memcpy(this->data, rhs.data, this->size);
    }
}


/*
 * vislib::RawStorage::~RawStorage
 */
vislib::RawStorage::~RawStorage(void) {
    SAFE_FREE(this->data);
}


/*
 * vislib::RawStorage::AssertSize
 */
bool vislib::RawStorage::AssertSize(const SIZE_T size, const bool keepContent) {
    if (this->size < size) {
        this->EnforceSize(size, keepContent);
        return true;

    } else {
        return false;
    }
}


/*
 * vislib::RawStorage::EnforceSize
 */
void vislib::RawStorage::EnforceSize(const SIZE_T size, 
                                     const bool keepContent) {
    
    if ((this->size = size) > 0) {
                                         
        if (keepContent) {
            TRACE(Trace::LEVEL_INFO, "RawStorage::AssertSize reallocates %u "
                "bytes.\n", this->size);
            this->data = ::realloc(this->data, this->size);

        } else {
            TRACE(Trace::LEVEL_INFO, "RawStorage::AssertSize allocates %u "
                "bytes.\n", this->size);
            SAFE_FREE(this->data);
            this->data = ::malloc(this->size);
        }

        if (this->data == NULL) {
            this->size = 0;
            throw std::bad_alloc();
        }

    } /* end if ((this->size = size) > 0) */
}


/*
 * vislib::RawStorage::operator =
 */
vislib::RawStorage& vislib::RawStorage::operator =(const RawStorage& rhs) {
    if (this != &rhs) {
        this->EnforceSize(rhs.size);
        ::memcpy(this->data, rhs.data, rhs.size);
        
        ASSERT(this->size == rhs.size);
    }

    return *this;
}

<commit_msg>Trace-Level changed to LEVEL_VL_INFO.<commit_after>/*
 * RawStorage.cpp
 *
 * Copyright (C) 2006 by Universitaet Stuttgart (VIS). Alle Rechte vorbehalten.
 */


#include "vislib/RawStorage.h"

#include <stdexcept>

#include "vislib/assert.h"
#include "vislib/memutils.h"
#include "vislib/Trace.h"


/*
 * vislib::RawStorage::RawStorage
 */
vislib::RawStorage::RawStorage(const SIZE_T size) : data(NULL), size(size) {
    this->EnforceSize(this->size);
}


/*
 * vislib::RawStorage::RawStorage
 */
vislib::RawStorage::RawStorage(const RawStorage& rhs) 
        : data(NULL), size(rhs.size) {
    if (this->size > 0) {
        this->EnforceSize(this->size);
        ::memcpy(this->data, rhs.data, this->size);
    }
}


/*
 * vislib::RawStorage::~RawStorage
 */
vislib::RawStorage::~RawStorage(void) {
    SAFE_FREE(this->data);
}


/*
 * vislib::RawStorage::AssertSize
 */
bool vislib::RawStorage::AssertSize(const SIZE_T size, const bool keepContent) {
    if (this->size < size) {
        this->EnforceSize(size, keepContent);
        return true;

    } else {
        return false;
    }
}


/*
 * vislib::RawStorage::EnforceSize
 */
void vislib::RawStorage::EnforceSize(const SIZE_T size, 
                                     const bool keepContent) {
    
    if ((this->size = size) > 0) {
                                         
        if (keepContent) {
            TRACE(Trace::LEVEL_VL_INFO, "RawStorage::AssertSize reallocates %u "
                "bytes.\n", this->size);
            this->data = ::realloc(this->data, this->size);

        } else {
            TRACE(Trace::LEVEL_VL_INFO, "RawStorage::AssertSize allocates %u "
                "bytes.\n", this->size);
            SAFE_FREE(this->data);
            this->data = ::malloc(this->size);
        }

        if (this->data == NULL) {
            this->size = 0;
            throw std::bad_alloc();
        }

    } /* end if ((this->size = size) > 0) */
}


/*
 * vislib::RawStorage::operator =
 */
vislib::RawStorage& vislib::RawStorage::operator =(const RawStorage& rhs) {
    if (this != &rhs) {
        this->EnforceSize(rhs.size);
        ::memcpy(this->data, rhs.data, rhs.size);
        
        ASSERT(this->size == rhs.size);
    }

    return *this;
}


{'fraction_non_alphanumeric': 0.163897620116749, 'fraction_numerical': 0.003592276605298608, 'mean_word_length': 2.3345808383233533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1423695', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1436, 'n_words': 253}