Commit 9cd015ac3765220030f4db1a78b6ec98dfa58439
Committed by
GitHub
1 parent
628dc920
Regards #340, #345: Removed unnecessary indentation of exceptions namespace + ad…
…ded end-of-namespace comment (#351)
Showing
1 changed file
with
124 additions
and
122 deletions
include/cxxopts.hpp
| ... | ... | @@ -371,154 +371,156 @@ class Value : public std::enable_shared_from_this<Value> |
| 371 | 371 | #pragma GCC diagnostic pop |
| 372 | 372 | #endif |
| 373 | 373 | namespace exceptions { |
| 374 | - class exception : public std::exception | |
| 375 | - { | |
| 376 | - public: | |
| 377 | - explicit exception(std::string message) | |
| 378 | - : m_message(std::move(message)) | |
| 379 | - { | |
| 380 | - } | |
| 381 | 374 | |
| 382 | - CXXOPTS_NODISCARD | |
| 383 | - const char* | |
| 384 | - what() const noexcept override | |
| 385 | - { | |
| 386 | - return m_message.c_str(); | |
| 387 | - } | |
| 388 | - | |
| 389 | - private: | |
| 390 | - std::string m_message; | |
| 391 | - }; | |
| 375 | +class exception : public std::exception | |
| 376 | +{ | |
| 377 | + public: | |
| 378 | + explicit exception(std::string message) | |
| 379 | + : m_message(std::move(message)) | |
| 380 | + { | |
| 381 | + } | |
| 392 | 382 | |
| 393 | - class specification : public exception | |
| 383 | + CXXOPTS_NODISCARD | |
| 384 | + const char* | |
| 385 | + what() const noexcept override | |
| 394 | 386 | { |
| 395 | - public: | |
| 387 | + return m_message.c_str(); | |
| 388 | + } | |
| 396 | 389 | |
| 397 | - explicit specification(const std::string& message) | |
| 398 | - : exception(message) | |
| 399 | - { | |
| 400 | - } | |
| 401 | - }; | |
| 390 | + private: | |
| 391 | + std::string m_message; | |
| 392 | +}; | |
| 402 | 393 | |
| 403 | - class parsing : public exception | |
| 404 | - { | |
| 405 | - public: | |
| 406 | - explicit parsing(const std::string& message) | |
| 407 | - : exception(message) | |
| 408 | - { | |
| 409 | - } | |
| 410 | - }; | |
| 394 | +class specification : public exception | |
| 395 | +{ | |
| 396 | + public: | |
| 411 | 397 | |
| 412 | - class option_already_exists : public specification | |
| 398 | + explicit specification(const std::string& message) | |
| 399 | + : exception(message) | |
| 413 | 400 | { |
| 414 | - public: | |
| 415 | - explicit option_already_exists(const std::string& option) | |
| 416 | - : specification("Option " + LQUOTE + option + RQUOTE + " already exists") | |
| 417 | - { | |
| 418 | - } | |
| 419 | - }; | |
| 401 | + } | |
| 402 | +}; | |
| 420 | 403 | |
| 421 | - class invalid_option_format : public specification | |
| 404 | +class parsing : public exception | |
| 405 | +{ | |
| 406 | + public: | |
| 407 | + explicit parsing(const std::string& message) | |
| 408 | + : exception(message) | |
| 422 | 409 | { |
| 423 | - public: | |
| 424 | - explicit invalid_option_format(const std::string& format) | |
| 425 | - : specification("Invalid option format " + LQUOTE + format + RQUOTE) | |
| 426 | - { | |
| 427 | - } | |
| 428 | - }; | |
| 410 | + } | |
| 411 | +}; | |
| 429 | 412 | |
| 430 | - class invalid_option_syntax : public parsing { | |
| 431 | - public: | |
| 432 | - explicit invalid_option_syntax(const std::string& text) | |
| 433 | - : parsing("Argument " + LQUOTE + text + RQUOTE + | |
| 434 | - " starts with a - but has incorrect syntax") | |
| 435 | - { | |
| 436 | - } | |
| 437 | - }; | |
| 413 | +class option_already_exists : public specification | |
| 414 | +{ | |
| 415 | + public: | |
| 416 | + explicit option_already_exists(const std::string& option) | |
| 417 | + : specification("Option " + LQUOTE + option + RQUOTE + " already exists") | |
| 418 | + { | |
| 419 | + } | |
| 420 | +}; | |
| 438 | 421 | |
| 439 | - class no_such_option : public parsing | |
| 422 | +class invalid_option_format : public specification | |
| 423 | +{ | |
| 424 | + public: | |
| 425 | + explicit invalid_option_format(const std::string& format) | |
| 426 | + : specification("Invalid option format " + LQUOTE + format + RQUOTE) | |
| 440 | 427 | { |
| 441 | - public: | |
| 442 | - explicit no_such_option(const std::string& option) | |
| 443 | - : parsing("Option " + LQUOTE + option + RQUOTE + " does not exist") | |
| 444 | - { | |
| 445 | - } | |
| 446 | - }; | |
| 428 | + } | |
| 429 | +}; | |
| 447 | 430 | |
| 448 | - class missing_argument : public parsing | |
| 431 | +class invalid_option_syntax : public parsing { | |
| 432 | + public: | |
| 433 | + explicit invalid_option_syntax(const std::string& text) | |
| 434 | + : parsing("Argument " + LQUOTE + text + RQUOTE + | |
| 435 | + " starts with a - but has incorrect syntax") | |
| 449 | 436 | { |
| 450 | - public: | |
| 451 | - explicit missing_argument(const std::string& option) | |
| 452 | - : parsing( | |
| 453 | - "Option " + LQUOTE + option + RQUOTE + " is missing an argument" | |
| 454 | - ) | |
| 455 | - { | |
| 456 | - } | |
| 457 | - }; | |
| 437 | + } | |
| 438 | +}; | |
| 458 | 439 | |
| 459 | - class option_requires_argument : public parsing | |
| 440 | +class no_such_option : public parsing | |
| 441 | +{ | |
| 442 | + public: | |
| 443 | + explicit no_such_option(const std::string& option) | |
| 444 | + : parsing("Option " + LQUOTE + option + RQUOTE + " does not exist") | |
| 460 | 445 | { |
| 461 | - public: | |
| 462 | - explicit option_requires_argument(const std::string& option) | |
| 463 | - : parsing( | |
| 464 | - "Option " + LQUOTE + option + RQUOTE + " requires an argument" | |
| 465 | - ) | |
| 466 | - { | |
| 467 | - } | |
| 468 | - }; | |
| 446 | + } | |
| 447 | +}; | |
| 469 | 448 | |
| 470 | - class gratuitous_argument_for_option : public parsing | |
| 449 | +class missing_argument : public parsing | |
| 450 | +{ | |
| 451 | + public: | |
| 452 | + explicit missing_argument(const std::string& option) | |
| 453 | + : parsing( | |
| 454 | + "Option " + LQUOTE + option + RQUOTE + " is missing an argument" | |
| 455 | + ) | |
| 471 | 456 | { |
| 472 | - public: | |
| 473 | - gratuitous_argument_for_option | |
| 474 | - ( | |
| 475 | - const std::string& option, | |
| 476 | - const std::string& arg | |
| 457 | + } | |
| 458 | +}; | |
| 459 | + | |
| 460 | +class option_requires_argument : public parsing | |
| 461 | +{ | |
| 462 | + public: | |
| 463 | + explicit option_requires_argument(const std::string& option) | |
| 464 | + : parsing( | |
| 465 | + "Option " + LQUOTE + option + RQUOTE + " requires an argument" | |
| 477 | 466 | ) |
| 478 | - : parsing( | |
| 479 | - "Option " + LQUOTE + option + RQUOTE + | |
| 480 | - " does not take an argument, but argument " + | |
| 481 | - LQUOTE + arg + RQUOTE + " given" | |
| 482 | - ) | |
| 483 | - { | |
| 484 | - } | |
| 485 | - }; | |
| 467 | + { | |
| 468 | + } | |
| 469 | +}; | |
| 486 | 470 | |
| 487 | - class requested_option_not_present : public parsing | |
| 471 | +class gratuitous_argument_for_option : public parsing | |
| 472 | +{ | |
| 473 | + public: | |
| 474 | + gratuitous_argument_for_option | |
| 475 | + ( | |
| 476 | + const std::string& option, | |
| 477 | + const std::string& arg | |
| 478 | + ) | |
| 479 | + : parsing( | |
| 480 | + "Option " + LQUOTE + option + RQUOTE + | |
| 481 | + " does not take an argument, but argument " + | |
| 482 | + LQUOTE + arg + RQUOTE + " given" | |
| 483 | + ) | |
| 488 | 484 | { |
| 489 | - public: | |
| 490 | - explicit requested_option_not_present(const std::string& option) | |
| 491 | - : parsing("Option " + LQUOTE + option + RQUOTE + " not present") | |
| 492 | - { | |
| 493 | - } | |
| 494 | - }; | |
| 485 | + } | |
| 486 | +}; | |
| 495 | 487 | |
| 496 | - class option_has_no_value : public exception | |
| 488 | +class requested_option_not_present : public parsing | |
| 489 | +{ | |
| 490 | + public: | |
| 491 | + explicit requested_option_not_present(const std::string& option) | |
| 492 | + : parsing("Option " + LQUOTE + option + RQUOTE + " not present") | |
| 497 | 493 | { |
| 498 | - public: | |
| 499 | - explicit option_has_no_value(const std::string& option) | |
| 500 | - : exception( | |
| 501 | - !option.empty() ? | |
| 502 | - ("Option " + LQUOTE + option + RQUOTE + " has no value") : | |
| 503 | - "Option has no value") | |
| 504 | - { | |
| 505 | - } | |
| 506 | - }; | |
| 494 | + } | |
| 495 | +}; | |
| 507 | 496 | |
| 508 | - class incorrect_argument_type : public parsing | |
| 497 | +class option_has_no_value : public exception | |
| 498 | +{ | |
| 499 | + public: | |
| 500 | + explicit option_has_no_value(const std::string& option) | |
| 501 | + : exception( | |
| 502 | + !option.empty() ? | |
| 503 | + ("Option " + LQUOTE + option + RQUOTE + " has no value") : | |
| 504 | + "Option has no value") | |
| 509 | 505 | { |
| 510 | - public: | |
| 511 | - explicit incorrect_argument_type | |
| 512 | - ( | |
| 513 | - const std::string& arg | |
| 506 | + } | |
| 507 | +}; | |
| 508 | + | |
| 509 | +class incorrect_argument_type : public parsing | |
| 510 | +{ | |
| 511 | + public: | |
| 512 | + explicit incorrect_argument_type | |
| 513 | + ( | |
| 514 | + const std::string& arg | |
| 515 | + ) | |
| 516 | + : parsing( | |
| 517 | + "Argument " + LQUOTE + arg + RQUOTE + " failed to parse" | |
| 514 | 518 | ) |
| 515 | - : parsing( | |
| 516 | - "Argument " + LQUOTE + arg + RQUOTE + " failed to parse" | |
| 517 | - ) | |
| 518 | - { | |
| 519 | - } | |
| 520 | - }; | |
| 521 | -} | |
| 519 | + { | |
| 520 | + } | |
| 521 | +}; | |
| 522 | + | |
| 523 | +} // namespace exceptions | |
| 522 | 524 | |
| 523 | 525 | template <typename T> |
| 524 | 526 | void throw_or_mimic(const std::string& text) | ... | ... |