Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Ycasas committed May 16, 2014
0 parents commit d593245
Show file tree
Hide file tree
Showing 41 changed files with 6,453 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store

61 changes: 61 additions & 0 deletions API/UniCString/C/APIUtils.hpp
@@ -0,0 +1,61 @@
#if !defined(UNICSTRING_API_C_UTILS_HPP)
#define UNICSTRING_API_C_UTILS_HPP

// This is an internal helper utilities for C API.

#include <UniCString/C/UniCTypes.h>
#include <Core/Exception.hpp>
#include <Core/String.hpp>

namespace UniCString
{
namespace API
{
namespace Utils
{

inline void CreateUniCErrorTFromException(const UniCString::Core::Exception& e, UniCErrorT* ucError)
{
if (ucError != NULLPTR)
*ucError = reinterpret_cast<UniCErrorT>(new UniCString::Core::Exception(e));
return;
}

inline void CreateUniCErrorTFromString(const char* message, UniCErrorT* ucError)
{
if (ucError != NULLPTR)
*ucError = reinterpret_cast<UniCErrorT>(new UniCString::Core::Exception(message));
return;
}

#define UC_BEGIN_TRY_BLOCK() \
UniCErrorT returnError = NULLPTR; \
try {

#define UC_END_TRY_BLOCK() \
} \
catch (UniCString::Core::Exception& e) { \
UniCString::API::Utils::CreateUniCErrorTFromException(e, &returnError); \
} \
catch (std::exception& e) { \
UniCString::API::Utils::CreateUniCErrorTFromString(e.what(), &returnError); \
} \
catch (...) { \
UniCString::API::Utils::CreateUniCErrorTFromString("Unknown Error.", &returnError); \
} \
return (returnError);

// dereferencing helpers
#define GET_EXCEPTION_PTR(ucError) ((UniCString::Core::Exception*) ucError)
#define GET_EXCEPTION_REF(ucError) ((UniCString::Core::Exception&) *(GET_EXCEPTION_PTR(ucError)))

#define GET_STRING_PTR(ucString) ((UniCString::Core::String*) ucString)
#define GET_STRING_REF(ucString) ((UniCString::Core::String&) *(GET_STRING_PTR(ucString)))

#define GET_CORE_STRING_ENCODING(ucEncoding) ((UniCString::Core::String::Encoding) ucEncoding)

} // namespace Utils
} // namespace API
} // namespace UniCString

#endif // UNICSTRING_API_C_UTILS_HPP
70 changes: 70 additions & 0 deletions API/UniCString/C/UniCError.cpp
@@ -0,0 +1,70 @@
#include "UniCError.h"

#include <limits>

#include <Core/Exception.hpp>

#include "APIUtils.hpp"

#if defined(__cplusplus)
extern "C"
{
#endif /* defined(__cplusplus) */

UC_API_SYMBOL_EXPORT
UniCBoolT UniCIsError(UniCErrorT ucError)
{
return (UniCBoolSet(ucError != NULLPTR));
}

UC_API_SYMBOL_EXPORT
const char* UniCErrorGetMessage(UniCErrorT ucError)
{
if (ucError == NULLPTR) return (NULLPTR);

return (GET_EXCEPTION_REF(ucError).GetMessage().c_str());
}

UC_API_SYMBOL_EXPORT
const char* UniCErrorGetFileName(UniCErrorT ucError)
{
if (ucError == NULLPTR) return (NULLPTR);

return (GET_EXCEPTION_REF(ucError).GetFileName().c_str());
}

UC_API_SYMBOL_EXPORT
const char* UniCErrorGetFunctionName(UniCErrorT ucError)
{
if (ucError == NULLPTR) return (NULLPTR);

return (GET_EXCEPTION_REF(ucError).GetFunctionName().c_str());
}

UC_API_SYMBOL_EXPORT
size_t UniCErrorGetLineNumber(UniCErrorT ucError)
{
if (ucError == NULLPTR) return (std::numeric_limits<size_t>::max());

return (GET_EXCEPTION_REF(ucError).GetLineNumber());
}

UC_API_SYMBOL_EXPORT
const char* UniCErrorGetFullMessage(UniCErrorT ucError)
{
if (ucError == NULLPTR) return (NULLPTR);

return (GET_EXCEPTION_REF(ucError).GetFullMessage().c_str());
}

UC_API_SYMBOL_EXPORT
void UniCErrorDestroy(UniCErrorT ucError)
{
if (ucError != NULLPTR)
delete (GET_EXCEPTION_PTR(ucError));
return;
}

#if defined(__cplusplus)
}
#endif /* defined(__cplusplus) */
72 changes: 72 additions & 0 deletions API/UniCString/C/UniCError.h
@@ -0,0 +1,72 @@
#if !defined(UNICSTRING_C_UNICERROR_H)
#define UNICSTRING_C_UNICERROR_H

#include <stddef.h>

#include <UniCString/C/UniCTypes.h>

#if defined(__cplusplus)
extern "C"
{
#endif /* defined(__cplusplus) */

/**
/// Checks whether the return code is an error.
/// @param ucError The handle to the error.
/// @returns UniCTrue if the return code is an error.
**/
UC_API_SYMBOL_EXPORT
UniCBoolT UniCIsError(UniCErrorT ucError);

/**
/// Gets the message describing the error.
/// @param ucError The handle to the error.
/// @returns The message describing the error.
**/
UC_API_SYMBOL_EXPORT
const char* UniCErrorGetMessage(UniCErrorT ucError);

/**
/// Gets the file name where the error happened.
/// @param ucError The handle to the error.
/// @return The file name where the error happened.
**/
UC_API_SYMBOL_EXPORT
const char* UniCErrorGetFileName(UniCErrorT ucError);

/**
/// Gets the name of the function which caused the error.
/// @param ucError The handle to the error.
/// @returns The name of the function which caused the error.
**/
UC_API_SYMBOL_EXPORT
const char* UniCErrorGetFunctionName(UniCErrorT ucError);

/**
/// Gets the line number in the file where the error happened.
/// @param ucError The handle to the error.
/// @returns The line number in the file where the error happened.
**/
UC_API_SYMBOL_EXPORT
size_t UniCErrorGetLineNumber(UniCErrorT ucError);

/**
/// Gets the full message describing the error.
/// @param ucError The handle to the error.
/// @returns The full message describing the error.
**/
UC_API_SYMBOL_EXPORT
const char* UniCErrorGetFullMessage(UniCErrorT ucError);

/**
/// Destroys the error instance.
/// @param ucError The handle to the error.
**/
UC_API_SYMBOL_EXPORT
void UniCErrorDestroy(UniCErrorT ucError);

#if defined(__cplusplus)
}
#endif /* defined(__cplusplus) */

#endif /* !defined(UNICSTRING_C_UNICERROR_H) */

0 comments on commit d593245

Please sign in to comment.