mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-03 15:34:06 +00:00
Compare commits
2 commits
608016208b
...
8fd5b37335
Author | SHA1 | Date | |
---|---|---|---|
8fd5b37335 | |||
4758f9e972 |
|
@ -17,7 +17,6 @@ Checks: >
|
||||||
portability-*,
|
portability-*,
|
||||||
readability-*,
|
readability-*,
|
||||||
-bugprone-easily-swappable-parameters,
|
-bugprone-easily-swappable-parameters,
|
||||||
-bugprone-reserved-identifier,
|
|
||||||
-cppcoreguidelines-owning-memory,
|
-cppcoreguidelines-owning-memory,
|
||||||
-cppcoreguidelines-prefer-member-initializer,
|
-cppcoreguidelines-prefer-member-initializer,
|
||||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||||
|
@ -44,5 +43,11 @@ CheckOptions:
|
||||||
value: 1
|
value: 1
|
||||||
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
|
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
|
||||||
value: 1
|
value: 1
|
||||||
|
- key: modernize-avoid-c-arrays.AllowStringArrays
|
||||||
|
value: 1
|
||||||
|
- key: cppcoreguidelines-avoid-c-arrays.AllowStringArrays
|
||||||
|
value: 1
|
||||||
|
- key: hicpp-avoid-c-arrays.AllowStringArrays
|
||||||
|
value: 1
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
|
@ -4,22 +4,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
|
||||||
/// A way to declare an exception class fast
|
/// A way to declare an exception class fast
|
||||||
/// Do like this:
|
/// Do like this:
|
||||||
/// DEF_EX( exErrorInFoo, "An error in foo encountered", std::exception )
|
/// DEF_EX( exErrorInFoo, "An error in foo encountered", std::exception )
|
||||||
/// DEF_EX( exFooNotFound, "Foo was not found", exErrorInFoo )
|
/// DEF_EX( exFooNotFound, "Foo was not found", exErrorInFoo )
|
||||||
|
|
||||||
#define DEF_EX( exName, exDescription, exParent ) \
|
#define DEF_EX( exName, exDescription, exParent ) \
|
||||||
class exName: public exParent \
|
constexpr static char ExStr_## exName[] = exDescription; \
|
||||||
{ \
|
using exName = defineEx< exParent, ExStr_## exName >;
|
||||||
public: \
|
|
||||||
virtual const char * what() const noexcept \
|
|
||||||
{ \
|
|
||||||
return ( exDescription ); \
|
|
||||||
} \
|
|
||||||
virtual ~exName() noexcept {} \
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Same as DEF_EX, but takes a runtime string argument, which gets concatenated
|
/// Same as DEF_EX, but takes a runtime string argument, which gets concatenated
|
||||||
/// with the description.
|
/// with the description.
|
||||||
|
@ -29,20 +24,36 @@
|
||||||
/// throw exCantOpen( "example.txt" );
|
/// throw exCantOpen( "example.txt" );
|
||||||
///
|
///
|
||||||
/// what() would return "can't open file example.txt"
|
/// what() would return "can't open file example.txt"
|
||||||
|
///
|
||||||
#define DEF_EX_STR( exName, exDescription, exParent ) \
|
#define DEF_EX_STR( exName, exDescription, exParent ) \
|
||||||
class exName: public exParent \
|
constexpr static char ExStr_## exName[] = exDescription; \
|
||||||
{ \
|
using exName = defineExStr< exParent, ExStr_## exName >;
|
||||||
std::string value; \
|
|
||||||
\
|
// clang-format on
|
||||||
public: \
|
|
||||||
explicit exName( std::string const & value_ ): \
|
template< typename ParentEx, const char * description >
|
||||||
value( std::string( exDescription ) + " " + value_ ) \
|
class defineEx: public ParentEx
|
||||||
{ \
|
{
|
||||||
} \
|
public:
|
||||||
virtual const char * what() const noexcept \
|
virtual const char * what() const noexcept
|
||||||
{ \
|
{
|
||||||
return value.c_str(); \
|
return description;
|
||||||
} \
|
}
|
||||||
virtual ~exName() noexcept {} \
|
};
|
||||||
|
|
||||||
|
template< typename ParentEx, const char * description >
|
||||||
|
class defineExStr: public ParentEx
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit defineExStr( std::string const & message_ ):
|
||||||
|
message( fmt::format( "{} {}", description, message_ ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual const char * what() const noexcept
|
||||||
|
{
|
||||||
|
return message.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,10 +46,6 @@ using BtreeIndexing::IndexInfo;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
DEF_EX_STR( exNotAardFile, "Not an AARD file", Dictionary::Ex )
|
|
||||||
DEF_EX_STR( exWordIsTooLarge, "Enountered a word that is too large:", Dictionary::Ex )
|
|
||||||
DEF_EX_STR( exSuddenEndOfFile, "Sudden end of file", Dictionary::Ex )
|
|
||||||
|
|
||||||
#pragma pack( push, 1 )
|
#pragma pack( push, 1 )
|
||||||
|
|
||||||
/// AAR file header
|
/// AAR file header
|
||||||
|
|
|
@ -169,10 +169,6 @@ void addEntryToIndex( string & word,
|
||||||
indexedWords.addWord( Utf8::decode( word ), articleOffset );
|
indexedWords.addWord( Utf8::decode( word ), articleOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DEF_EX( exFailedToDecompressArticle, "Failed to decompress article's body", Dictionary::Ex )
|
|
||||||
DEF_EX( exChunkIndexOutOfRange, "Chunk index is out of range", Dictionary::Ex )
|
|
||||||
|
|
||||||
class BglDictionary: public BtreeIndexing::BtreeDictionary
|
class BglDictionary: public BtreeIndexing::BtreeDictionary
|
||||||
{
|
{
|
||||||
QMutex idxMutex;
|
QMutex idxMutex;
|
||||||
|
|
|
@ -301,7 +301,6 @@ namespace {
|
||||||
////////////////// GLS Dictionary
|
////////////////// GLS Dictionary
|
||||||
|
|
||||||
using Dictionary::exCantReadFile;
|
using Dictionary::exCantReadFile;
|
||||||
DEF_EX( exUserAbort, "User abort", Dictionary::Ex )
|
|
||||||
DEF_EX_STR( exDictzipError, "DICTZIP error", Dictionary::Ex )
|
DEF_EX_STR( exDictzipError, "DICTZIP error", Dictionary::Ex )
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -64,14 +64,11 @@ DEF_EX( exNotAnIfoFile, "Not an .ifo file", Dictionary::Ex )
|
||||||
DEF_EX_STR( exBadFieldInIfo, "Bad field in .ifo file encountered:", Dictionary::Ex )
|
DEF_EX_STR( exBadFieldInIfo, "Bad field in .ifo file encountered:", Dictionary::Ex )
|
||||||
DEF_EX_STR( exNoIdxFile, "No corresponding .idx file was found for", Dictionary::Ex )
|
DEF_EX_STR( exNoIdxFile, "No corresponding .idx file was found for", Dictionary::Ex )
|
||||||
DEF_EX_STR( exNoDictFile, "No corresponding .dict file was found for", Dictionary::Ex )
|
DEF_EX_STR( exNoDictFile, "No corresponding .dict file was found for", Dictionary::Ex )
|
||||||
DEF_EX_STR( exNoSynFile, "No corresponding .syn file was found for", Dictionary::Ex )
|
|
||||||
|
|
||||||
DEF_EX( ex64BitsNotSupported, "64-bit indices are not presently supported, sorry", Dictionary::Ex )
|
DEF_EX( ex64BitsNotSupported, "64-bit indices are not presently supported, sorry", Dictionary::Ex )
|
||||||
DEF_EX( exDicttypeNotSupported, "Dictionaries with dicttypes are not supported, sorry", Dictionary::Ex )
|
DEF_EX( exDicttypeNotSupported, "Dictionaries with dicttypes are not supported, sorry", Dictionary::Ex )
|
||||||
|
|
||||||
using Dictionary::exCantReadFile;
|
using Dictionary::exCantReadFile;
|
||||||
DEF_EX_STR( exWordIsTooLarge, "Enountered a word that is too large:", Dictionary::Ex )
|
|
||||||
DEF_EX_STR( exSuddenEndOfFile, "Sudden end of file", Dictionary::Ex )
|
|
||||||
DEF_EX_STR( exDictzipError, "DICTZIP error", Dictionary::Ex )
|
DEF_EX_STR( exDictzipError, "DICTZIP error", Dictionary::Ex )
|
||||||
|
|
||||||
DEF_EX_STR( exIncorrectOffset, "Incorrect offset encountered in file", Dictionary::Ex )
|
DEF_EX_STR( exIncorrectOffset, "Incorrect offset encountered in file", Dictionary::Ex )
|
||||||
|
|
|
@ -81,7 +81,6 @@ namespace {
|
||||||
|
|
||||||
using Dictionary::exCantReadFile;
|
using Dictionary::exCantReadFile;
|
||||||
DEF_EX_STR( exNotXdxfFile, "The file is not an XDXF file:", Dictionary::Ex )
|
DEF_EX_STR( exNotXdxfFile, "The file is not an XDXF file:", Dictionary::Ex )
|
||||||
DEF_EX( exCorruptedIndex, "The index file is corrupted", Dictionary::Ex )
|
|
||||||
DEF_EX_STR( exDictzipError, "DICTZIP error", Dictionary::Ex )
|
DEF_EX_STR( exDictzipError, "DICTZIP error", Dictionary::Ex )
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
Loading…
Reference in a new issue