Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes more functions noexcept #1578

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions gluecodium/src/main/resources/templates/cpp/common/Locale.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ namespace {{.}} {
/**
* Represents an ISO locale, optionally with a corresponding BCP 47 language tag.
*/
struct {{>cpp/CppExportMacro}}Locale {
Locale();
explicit Locale(std::optional<std::string> language_tag);
Locale(std::optional<std::string> language_code, std::optional<std::string> country_code);
struct {{>cpp/CppExportMacro}}Locale final {
Locale() noexcept;
explicit Locale(std::optional<std::string> language_tag) noexcept;
Locale(std::optional<std::string> language_code, std::optional<std::string> country_code) noexcept;
Locale(std::optional<std::string> language_code,
std::optional<std::string> country_code,
std::optional<std::string> script_code);
std::optional<std::string> script_code) noexcept;
Locale(std::optional<std::string> language_code,
std::optional<std::string> country_code,
std::optional<std::string> script_code,
std::optional<std::string> language_tag);
explicit Locale(std::string language_tag);
Locale(std::string language_code, std::string country_code);
std::optional<std::string> language_tag) noexcept;
explicit Locale(std::string language_tag) noexcept;
Locale(std::string language_code, std::string country_code) noexcept;
Locale(std::string language_code,
std::string country_code,
std::string script_code);
std::string script_code) noexcept;
Locale(std::string language_code,
std::string country_code,
std::string script_code,
std::string language_tag);
std::string language_tag) noexcept;

/// ISO 639-1 language code (2-letter)
std::optional<std::string> language_code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,48 @@
namespace {{.}} {
{{/internalNamespace}}

Locale::Locale() {}
Locale::Locale() noexcept = default;

Locale::Locale(std::optional<std::string> language_tag) : language_tag(std::move(language_tag)) {}
Locale::Locale(std::optional<std::string> language_tag) noexcept : language_tag(std::move(language_tag)) {}

Locale::Locale(std::optional<std::string> language_code, std::optional<std::string> country_code)
Locale::Locale(std::optional<std::string> language_code, std::optional<std::string> country_code) noexcept
: language_code(std::move(language_code)),
country_code(std::move(country_code)) {}

Locale::Locale(std::optional<std::string> language_code,
std::optional<std::string> country_code,
std::optional<std::string> script_code)
std::optional<std::string> script_code) noexcept
: language_code(std::move(language_code)),
country_code(std::move(country_code)),
script_code(std::move(script_code)) {}

Locale::Locale(std::optional<std::string> language_code,
std::optional<std::string> country_code,
std::optional<std::string> script_code,
std::optional<std::string> language_tag)
std::optional<std::string> language_tag) noexcept
: language_code(std::move(language_code)),
country_code(std::move(country_code)),
script_code(std::move(script_code)),
language_tag(std::move(language_tag)) {}

Locale::Locale(std::string language_tag)
Locale::Locale(std::string language_tag) noexcept
: language_tag(std::optional<std::string>(std::move(language_tag))) {}

Locale::Locale(std::string language_code, std::string country_code)
Locale::Locale(std::string language_code, std::string country_code) noexcept
: language_code(std::optional<std::string>(std::move(language_code))),
country_code(std::optional<std::string>(std::move(country_code))) {}

Locale::Locale(std::string language_code,
std::string country_code,
std::string script_code)
std::string script_code) noexcept
: language_code(std::optional<std::string>(std::move(language_code))),
country_code(std::optional<std::string>(std::move(country_code))),
script_code(std::optional<std::string>(std::move(script_code))) {}

Locale::Locale(std::string language_code,
std::string country_code,
std::string script_code,
std::string language_tag)
std::string language_tag) noexcept
: language_code(std::optional<std::string>(std::move(language_code))),
country_code(std::optional<std::string>(std::move(country_code))),
script_code(std::optional<std::string>(std::move(script_code))),
Expand All @@ -95,18 +95,10 @@ bool
Locale::operator==(const Locale& rhs) const
{
return
((language_code && rhs.language_code)
? (*language_code == *rhs.language_code)
: (static_cast<bool>(language_code) == static_cast<bool>(rhs.language_code))) &&
((country_code && rhs.country_code)
? (*country_code == *rhs.country_code)
: (static_cast<bool>(country_code) == static_cast<bool>(rhs.country_code))) &&
((script_code && rhs.script_code)
? (*script_code == *rhs.script_code)
: (static_cast<bool>(script_code) == static_cast<bool>(rhs.script_code))) &&
((language_tag && rhs.language_tag)
? (*language_tag == *rhs.language_tag)
: (static_cast<bool>(language_tag) == static_cast<bool>(rhs.language_tag)));
(language_code == rhs.language_code) &&
(country_code == rhs.country_code) &&
(script_code == rhs.script_code) &&
(language_tag == rhs.language_tag);
}

bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace {{.}} {

using TypeId = std::string_view;

class {{>cpp/CppExportMacro}}TypeRepository
class {{>cpp/CppExportMacro}}TypeRepository final
{
public:
TypeRepository();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ namespace {{.}}
namespace jni
{

JNIEXPORT JavaVM* get_java_vm( );
JNIEXPORT JavaVM* get_java_vm( ) noexcept;

JNIEXPORT JNIEnv* getJniEnvironmentForCurrentThread( );
JNIEXPORT JNIEnv* getJniEnvironmentForCurrentThread( ) noexcept;

}
{{#internalNamespace}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ namespace jni
{

JavaVM*
get_java_vm( )
get_java_vm( ) noexcept
{
return jvm;
}


JNIEnv* getJniEnvironmentForCurrentThread( )
JNIEnv* getJniEnvironmentForCurrentThread( ) noexcept
{
// Add cleanup callback to current thread when called the first time
static pthread_once_t s_key_once = PTHREAD_ONCE_INIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private:
void do_init(JNIEnv* env);
virtual JniReference<jclass>* set_java_class(JniReference<jclass> java_class_reference) = 0;

const char* m_name;
const char* m_cpp_name;
const char* const m_name;
const char* const m_cpp_name;
};

template <class ... CppTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace jni
public:
explicit JniExceptionThrower(JNIEnv* jni_env) noexcept;

~JniExceptionThrower();
~JniExceptionThrower() noexcept;

void register_exception(JniReference<jobject> exception) noexcept;
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ JniExceptionThrower::JniExceptionThrower(JNIEnv* jni_env) noexcept : m_jni_env(j
{
}

JniExceptionThrower::~JniExceptionThrower()
JniExceptionThrower::~JniExceptionThrower() noexcept
{
if (m_exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,30 @@
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

#pragma once
#include "ExportCommonGluecodiumCpp.h"
#include <string_view>

namespace gluecodium {

using TypeId = std::string_view;
class _GLUECODIUM_CPP_EXPORT TypeRepository

class _GLUECODIUM_CPP_EXPORT TypeRepository final
{
public:
TypeRepository();
~TypeRepository();

void add_type(const void* instance, const TypeId& id);
TypeId get_id(const void* instance) const;
void remove_type(const void* instance);

private:
struct Impl;
Impl* pimpl;
};

_GLUECODIUM_CPP_EXPORT TypeRepository& get_type_repository();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,40 @@
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

#pragma once

#include "ExportCommonGluecodiumCpp.h"
#include "Hash.h"
#include <optional>
#include <string>

namespace gluecodium {

/**
* Represents an ISO locale, optionally with a corresponding BCP 47 language tag.
*/
struct _GLUECODIUM_CPP_EXPORT Locale {
Locale();
explicit Locale(std::optional<std::string> language_tag);
Locale(std::optional<std::string> language_code, std::optional<std::string> country_code);
struct _GLUECODIUM_CPP_EXPORT Locale final {
Locale() noexcept;
explicit Locale(std::optional<std::string> language_tag) noexcept;
Locale(std::optional<std::string> language_code, std::optional<std::string> country_code) noexcept;
Locale(std::optional<std::string> language_code,
std::optional<std::string> country_code,
std::optional<std::string> script_code);
std::optional<std::string> script_code) noexcept;
Locale(std::optional<std::string> language_code,
std::optional<std::string> country_code,
std::optional<std::string> script_code,
std::optional<std::string> language_tag);
explicit Locale(std::string language_tag);
Locale(std::string language_code, std::string country_code);
std::optional<std::string> language_tag) noexcept;
explicit Locale(std::string language_tag) noexcept;
Locale(std::string language_code, std::string country_code) noexcept;
Locale(std::string language_code,
std::string country_code,
std::string script_code);
std::string script_code) noexcept;
Locale(std::string language_code,
std::string country_code,
std::string script_code,
std::string language_tag);
std::string language_tag) noexcept;

/// ISO 639-1 language code (2-letter)
std::optional<std::string> language_code;
/// ISO 3166-1 alpha-2 country code (2-letter)
Expand All @@ -54,12 +59,15 @@ struct _GLUECODIUM_CPP_EXPORT Locale {
std::optional<std::string> script_code;
/// BCP 47 language tag
std::optional<std::string> language_tag;

bool operator==(const Locale& rhs) const;
bool operator!=(const Locale& rhs) const;
};

template<>
struct hash<Locale>
{
size_t operator()(const Locale& t) const noexcept;
};

}
Loading