<commit_before>/*
 * Copyright 2014-2018 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef INCLUDED_AERON_UTIL_EXCEPTIONS_FILE__
#define INCLUDED_AERON_UTIL_EXCEPTIONS_FILE__

#include <cstdint>
#include <string>
#include <stdexcept>
#include <sstream>
#include "MacroUtil.h"

namespace aeron { namespace util {


static constexpr const char* past_prefix(const char * const prefix, const char * const filename)
{
    return
        *prefix == *filename ? past_prefix(prefix + 1, filename + 1) :
            *filename == '/' ? filename + 1 : filename;
}

#define __SHORT_FILE__ aeron::util::past_prefix(__CMAKE_SOURCE_DIR__,__FILE__)

#ifdef _MSC_VER
    #define SOURCEINFO __FUNCTION__,  __SHORT_FILE__, __LINE__
    #if _MSC_VER >= 1900
        #define AERON_NOEXCEPT noexcept
    #else
        #define AERON_NOEXCEPT throw()
    #endif
#else
    #define SOURCEINFO  __PRETTY_FUNCTION__,  __SHORT_FILE__, __LINE__
    #define AERON_NOEXCEPT noexcept
#endif

class SourcedException : public std::exception
{
private:
    std::string m_where;
    std::string m_what;

public:
    SourcedException(const std::string &what, const std::string& function, const std::string& file, const int line) :
        m_where(reinterpret_cast<std::ostringstream&>(std::ostringstream() << function << " : " << file  << " : " << line).str()),
        m_what(what)
    {
    }

    virtual const char *what() const AERON_NOEXCEPT
    {
        return m_what.c_str();
    }

    const char *where() const AERON_NOEXCEPT
    {
        return m_where.c_str();
    }
};

#define DECLARE_SOURCED_EXCEPTION(exceptionName)                                            \
            class exceptionName : public aeron::util::SourcedException                      \
            {                                                                               \
                public:                                                                     \
                    exceptionName (const std::string &what, const std::string& function, const std::string& file, const int line) \<commit_msg>[c++] Simplify code by removing string stream use.<commit_after>/*
 * Copyright 2014-2018 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef INCLUDED_AERON_UTIL_EXCEPTIONS_FILE__
#define INCLUDED_AERON_UTIL_EXCEPTIONS_FILE__

#include <cstdint>
#include <string>
#include <stdexcept>
#include "MacroUtil.h"

namespace aeron { namespace util {


static constexpr const char* past_prefix(const char * const prefix, const char * const filename)
{
    return
        *prefix == *filename ? past_prefix(prefix + 1, filename + 1) :
            *filename == '/' ? filename + 1 : filename;
}

#define __SHORT_FILE__ aeron::util::past_prefix(__CMAKE_SOURCE_DIR__,__FILE__)

#ifdef _MSC_VER
    #define SOURCEINFO __FUNCTION__,  __SHORT_FILE__, __LINE__
    #if _MSC_VER >= 1900
        #define AERON_NOEXCEPT noexcept
    #else
        #define AERON_NOEXCEPT throw()
    #endif
#else
    #define SOURCEINFO  __PRETTY_FUNCTION__,  __SHORT_FILE__, __LINE__
    #define AERON_NOEXCEPT noexcept
#endif

class SourcedException : public std::exception
{
private:
    std::string m_where;
    std::string m_what;

public:
    SourcedException(const std::string &what, const std::string& function, const std::string& file, const int line) :
        m_where(function + " : " + file + " : " + std::to_string(line)),
        m_what(what)
    {
    }

    virtual const char * what() const AERON_NOEXCEPT
    {
        return m_what.c_str();
    }

    const char * where() const AERON_NOEXCEPT
    {
        return m_where.c_str();
    }
};

#define DECLARE_SOURCED_EXCEPTION(exceptionName)                                            \
            class exceptionName : public aeron::util::SourcedException                      \
            {                                                                               \
                public:                                                                     \
                    exceptionName (const std::string &what, const std::string& function, const std::string& file, const int line) \
{'fraction_non_alphanumeric': 0.08840635905389686, 'fraction_numerical': 0.007367196587824738, 'mean_word_length': 2.4694014794889037, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4881362', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1405, 'n_words': 440}