Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/cxxhl/src/exception.cpp view on Meta::CPAN
/**
* @copyright
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
* @endcopyright
*/
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <new>
#include <sstream>
#include "svncxxhl/exception.hpp"
#include "svn_error.h"
#include "svn_utf.h"
#include "private/svn_atomic.h"
#include "private/svn_error_private.h"
#include "svn_private_config.h"
#undef TRUE
#undef FALSE
namespace subversion {
namespace cxxhl {
namespace detail {
class error_description
{
public:
static error_description* create(const char* message,
const char *loc_file, long loc_line,
bool trace_link)
{
bool empty_message = (message == NULL);
const std::size_t length = (empty_message ? 0 : std::strlen(message));
void *memblock = ::operator new(length + sizeof(error_description));
error_description* description = new(memblock) error_description(
loc_file, loc_line, trace_link, empty_message);
if (length)
std::memcpy(description->m_message, message, length);
description->m_message[length] = 0;
return description;
}
static error_description* create(const char* message)
{
return create(message, NULL, 0, false);
}
error_description* reference() throw()
{
if (this)
svn_atomic_inc(&m_refcount);
return this;
}
error_description* dereference() throw()
{
if (this && 0 == svn_atomic_dec(&m_refcount))
{
this->~error_description();
::operator delete(this, std::nothrow);
return NULL;
}
return this;
}
const char* what() const throw() { return (m_empty ? NULL : m_message); }
const char* file() const throw() { return m_loc_file; }
long line() const throw() { return m_loc_line; }
bool trace() const throw() { return m_trace; }
private:
error_description(const char *loc_file, long loc_line,
bool trace_link, bool empty_message) throw()
: m_loc_file(loc_file),
m_loc_line(loc_line),
m_trace(trace_link),
m_empty(empty_message),
m_refcount(0)
{}
~error_description() throw() {}
const char* m_loc_file;
long m_loc_line;
bool m_trace;
bool m_empty;
( run in 1.252 second using v1.01-cache-2.11-cpan-524268b4103 )