diff options
author | David Tardon <dtardon@redhat.com> | 2014-07-13 19:20:37 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-07-13 19:20:59 +0200 |
commit | f5ad1320e3b55936947fc1cbac0892dcf0467021 (patch) | |
tree | c006a58de720a86b6d026ac29b0a5bfd51475605 | |
parent | 5b880a63d15fb895c1a302d7a41e91945390ce90 (diff) |
bool as result is enough
-rw-r--r-- | inc/libsdf/SDFDocument.h | 48 | ||||
-rw-r--r-- | src/conv/html/sdf2html.cpp | 7 | ||||
-rw-r--r-- | src/conv/raw/sdf2raw.cpp | 6 | ||||
-rw-r--r-- | src/conv/text/sdf2text.cpp | 7 | ||||
-rw-r--r-- | src/lib/SDFDocument.cpp | 56 |
5 files changed, 17 insertions, 107 deletions
diff --git a/inc/libsdf/SDFDocument.h b/inc/libsdf/SDFDocument.h index c85664c..491d1f5 100644 --- a/inc/libsdf/SDFDocument.h +++ b/inc/libsdf/SDFDocument.h @@ -29,52 +29,8 @@ namespace libsdf class SDFDocument { public: - /** Likelihood that the file format is supported. - */ - enum Confidence - { - CONFIDENCE_NONE, //< not supported - CONFIDENCE_WEAK, //< maybe supported - CONFIDENCE_UNSUPPORTED_ENCRYPTION, //< the format is supported, but the used encryption method is not - CONFIDENCE_SUPPORTED_ENCRYPTION, //< the format is supported, but encrypted - CONFIDENCE_SUPPORTED_PART, //< the file is only a part of a supported structured format - CONFIDENCE_EXCELLENT //< supported - }; - - /** Result of parsing the file. - */ - enum Result - { - RESULT_OK, //< parsed without any problem - RESULT_FILE_ACCESS_ERROR, //< problem when accessing the file - RESULT_PACKAGE_ERROR, //< problem with parsing structured file's content - RESULT_PARSE_ERROR, //< problem when parsing the file - RESULT_PASSWORD_MISMATCH, //< problem with given password - RESULT_UNSUPPORTED_ENCRYPTION, //< unsupported encryption - RESULT_UNSUPPORTED_FORMAT, //< unsupported file format - RESULT_UNKNOWN_ERROR //< an unspecified error - }; - - /** Type of document. - */ - enum Type - { - TYPE_UNKNOWN, //< unrecognized file - - TYPE_RESERVED1, //< reserved for future use - TYPE_RESERVED2, //< reserved for future use - TYPE_RESERVED3, //< reserved for future use - TYPE_RESERVED4, //< reserved for future use - TYPE_RESERVED5, //< reserved for future use - TYPE_RESERVED6, //< reserved for future use - TYPE_RESERVED7, //< reserved for future use - TYPE_RESERVED8, //< reserved for future use - TYPE_RESERVED9 //< reserved for future use - }; - - static SDFAPI Confidence isSupported(librevenge::RVNGInputStream *input, Type *type = 0); - static SDFAPI Result parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document, const char *password = 0); - static SDFAPI Result parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document, Type type, const char *password = 0); + static SDFAPI bool isSupported(librevenge::RVNGInputStream *input); + static SDFAPI bool parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document); }; } // namespace libsdf diff --git a/src/conv/html/sdf2html.cpp b/src/conv/html/sdf2html.cpp index e95c70b..3b5c99c 100644 --- a/src/conv/html/sdf2html.cpp +++ b/src/conv/html/sdf2html.cpp @@ -75,16 +75,13 @@ int main(int argc, char *argv[]) boost::shared_ptr<librevenge::RVNGInputStream> input(new librevenge::RVNGFileStream(szInputFile)); - SDFDocument::Type type = SDFDocument::TYPE_UNKNOWN; - SDFDocument::Confidence confidence = SDFDocument::isSupported(input.get(), &type); - - if ((SDFDocument::CONFIDENCE_EXCELLENT != confidence) && (SDFDocument::CONFIDENCE_WEAK != confidence)) + if (!SDFDocument::isSupported(input.get())) return 1; librevenge::RVNGString document; librevenge::RVNGTextTextGenerator documentGenerator(document, isInfo); - if (SDFDocument::RESULT_OK != SDFDocument::parse(input.get(), &documentGenerator, type)) + if (!SDFDocument::parse(input.get(), &documentGenerator)) return 1; printf("%s", document.cstr()); diff --git a/src/conv/raw/sdf2raw.cpp b/src/conv/raw/sdf2raw.cpp index e68ebf8..d42675f 100644 --- a/src/conv/raw/sdf2raw.cpp +++ b/src/conv/raw/sdf2raw.cpp @@ -75,12 +75,12 @@ int main(int argc, char *argv[]) boost::shared_ptr<librevenge::RVNGInputStream> input(new librevenge::RVNGFileStream(file)); - SDFDocument::Type type = SDFDocument::TYPE_UNKNOWN; - SDFDocument::Confidence confidence = SDFDocument::isSupported(input.get(), &type); + if (!SDFDocument::isSupported(input.get())) + return 1; librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel); - return (SDFDocument::RESULT_OK == SDFDocument::parse(input.get(), &documentGenerator, type)) ? 0 : 1; + return SDFDocument::parse(input.get(), &documentGenerator) ? 0 : 1; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/conv/text/sdf2text.cpp b/src/conv/text/sdf2text.cpp index 2d1aaa6..937c3f2 100644 --- a/src/conv/text/sdf2text.cpp +++ b/src/conv/text/sdf2text.cpp @@ -75,16 +75,13 @@ int main(int argc, char *argv[]) boost::shared_ptr<librevenge::RVNGInputStream> input(new librevenge::RVNGFileStream(szInputFile)); - SDFDocument::Type type = SDFDocument::TYPE_UNKNOWN; - SDFDocument::Confidence confidence = SDFDocument::isSupported(input.get(), &type); - - if ((SDFDocument::CONFIDENCE_EXCELLENT != confidence) && (SDFDocument::CONFIDENCE_WEAK != confidence)) + if (!SDFDocument::isSupported(input.get())) return 1; librevenge::RVNGString document; librevenge::RVNGTextTextGenerator documentGenerator(document, isInfo); - if (SDFDocument::RESULT_OK != SDFDocument::parse(input.get(), &documentGenerator, type)) + if (!SDFDocument::parse(input.get(), &documentGenerator)) return 1; printf("%s", document.cstr()); diff --git a/src/lib/SDFDocument.cpp b/src/lib/SDFDocument.cpp index 2e93d42..867f179 100644 --- a/src/lib/SDFDocument.cpp +++ b/src/lib/SDFDocument.cpp @@ -29,69 +29,29 @@ using std::equal; namespace libsdf { -SDFAPI SDFDocument::Confidence SDFDocument::isSupported(librevenge::RVNGInputStream *const input, Type *const type) try +SDFAPI bool SDFDocument::isSupported(librevenge::RVNGInputStream *const input) try { - if (type) - *type = TYPE_UNKNOWN; - - return CONFIDENCE_NONE; + return false; } catch (...) { - return CONFIDENCE_NONE; -} - -SDFAPI SDFDocument::Result SDFDocument::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const char *const) -{ - Type type; - Confidence confidence = isSupported(input, &type); - if (CONFIDENCE_NONE == confidence) - return RESULT_UNSUPPORTED_FORMAT; - else if (CONFIDENCE_SUPPORTED_PART == confidence) - return RESULT_UNSUPPORTED_FORMAT; - else if (CONFIDENCE_UNSUPPORTED_ENCRYPTION == confidence) - return RESULT_UNSUPPORTED_ENCRYPTION; - - return parse(input, document, type); + return false; } -SDFAPI SDFDocument::Result SDFDocument::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const SDFDocument::Type type, const char *const) try +SDFAPI bool SDFDocument::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document) try { - // sanity check - if (SDFDocument::TYPE_UNKNOWN == type) - return SDFDocument::RESULT_UNSUPPORTED_FORMAT; - if (SDFDocument::TYPE_RESERVED1 <= type) - return SDFDocument::RESULT_UNSUPPORTED_FORMAT; + if (!isSupported(input)) + return false; const RVNGInputStreamPtr_t input_(input, SDFDummyDeleter()); input_->seek(0, librevenge::RVNG_SEEK_SET); - return RESULT_UNKNOWN_ERROR; -} -catch (const FileAccessError &) -{ - return RESULT_FILE_ACCESS_ERROR; -} -catch (const PackageError &) -{ - return RESULT_PACKAGE_ERROR; -} -catch (const PasswordMismatch &) -{ - return RESULT_PASSWORD_MISMATCH; -} -catch (const UnsupportedEncryption &) -{ - return RESULT_UNSUPPORTED_ENCRYPTION; -} -catch (const UnsupportedFormat &) -{ - return RESULT_UNSUPPORTED_FORMAT; + return false; } catch (...) { - return RESULT_UNKNOWN_ERROR; + return false; } } // namespace libsdf |