Open
Conversation
- Introduced a new structure for status codes in status_codes.h, categorizing errors into Configuration, Connection, Io, Control, and Monitor. - Removed the obsolete status_codes.hpp file, consolidating functionality into status_codes.h. - Updated validation functions in validation.hpp to utilize the new status code structure for improved error handling. - Adjusted documentation in serial_abort_read.h and serial_abort_write.h to reflect changes in status code usage.
- Changed ValueType from std::int32_t to std::int64_t for improved range. - Replaced the make function with a GenCode template structure for generating error codes, enhancing clarity and maintainability. - Updated error codes in Configuration, Connection, Io, Control, and Monitor categories to utilize the new GenCode structure.
- Added an explicit conversion operator to the GenCode template for improved usability. - Updated status code definitions in Configuration, Connection, Io, Control, and Monitor categories to utilize the GenCode structure directly, enhancing clarity and maintainability.
- Moved status code definitions into a new cpp_core::status_codes namespace for better modularity. - Introduced a detail namespace to encapsulate internal structures, enhancing code clarity. - Updated references to ValueType and CategoryBase to reflect the new namespace structure, improving maintainability.
Mqxx
requested changes
Mar 18, 2026
…de definitions and improve code clarity.
- Introduced a new header file status_code.h to define a structured approach for status codes within the cpp_core::status_codes namespace. - Implemented a CategoryBase template for generating error codes, enhancing clarity and maintainability. - Organized status codes into categories: Configuration, Connection, Io, and Control, each with specific error codes for improved usability.
- Changed the CategoryBase template to accept a derived type instead of a category value, enhancing type safety and clarity. - Updated the Configuration, Connection, Io, and Control structs to define their category codes directly, improving maintainability and readability of status code definitions.
- Changed the initialization of kCategoryMultiplier from an assignment to a uniform initialization syntax, enhancing code consistency and clarity.
- Introduced CPP_CORE_STATUS_CATEGORY and CPP_CORE_CODE macros for streamlined status code definitions, improving maintainability and readability. - Added isError and isSuccess functions for better error handling. - Updated the CategoryBase template to support compile-time code generation, enhancing type safety and clarity in status code management.
- Moved isError, isSuccess, and belongsTo functions into the StatusCode struct for better encapsulation and organization. - Updated function signatures to use detail::ValueType for consistency with the new structure. - Removed redundant definitions from the detail namespace, enhancing code clarity and maintainability.
2c35c6e to
2b63c69
Compare
- Refactored the Code template to accept a Category type, improving type safety and clarity. - Introduced new member functions for retrieving the name and category of status codes. - Replaced macro-based status code definitions with structured definitions for Configuration, Connection, and Io categories, enhancing maintainability and readability.
Mqxx
requested changes
Mar 20, 2026
include/cpp_core/status_code.h
Outdated
Comment on lines
+136
to
+165
| // Test cases | ||
| static_assert(cpp_core::StatusCode::kSuccess == 0); | ||
| static_assert(cpp_core::StatusCode::isSuccess(cpp_core::StatusCode::kSuccess)); | ||
| static_assert(!cpp_core::StatusCode::isError(cpp_core::StatusCode::kSuccess)); | ||
|
|
||
| static_assert(cpp_core::StatusCode::Configuration::kSetBaudrateError == -100); | ||
| static_assert(cpp_core::StatusCode::Configuration::kSetDataBitsError == -101); | ||
| static_assert(cpp_core::StatusCode::Configuration::kSetParityError == -102); | ||
| static_assert(cpp_core::StatusCode::Configuration::kSetStopBitsError == -103); | ||
| static_assert(cpp_core::StatusCode::Configuration::kSetFlowControlError == -104); | ||
| static_assert(cpp_core::StatusCode::Configuration::kSetTimeoutError == -105); | ||
|
|
||
| static_assert(cpp_core::StatusCode::Connection::kNotFoundError == -200); | ||
| static_assert(cpp_core::StatusCode::Connection::kInvalidHandleError == -201); | ||
| static_assert(cpp_core::StatusCode::Connection::kCloseHandleError == -202); | ||
|
|
||
| static_assert(cpp_core::StatusCode::Io::kReadError == -300); | ||
| static_assert(cpp_core::StatusCode::Io::kWriteError == -301); | ||
| static_assert(cpp_core::StatusCode::Io::kAbortReadError == -302); | ||
| static_assert(cpp_core::StatusCode::Io::kAbortWriteError == -303); | ||
| static_assert(cpp_core::StatusCode::Io::kBufferError == -304); | ||
| static_assert(cpp_core::StatusCode::Io::kClearBufferInError == -305); | ||
| static_assert(cpp_core::StatusCode::Io::kClearBufferOutError == -306); | ||
|
|
||
| static_assert(cpp_core::StatusCode::Control::kSetDtrError == -400); | ||
| static_assert(cpp_core::StatusCode::Control::kSetRtsError == -401); | ||
| static_assert(cpp_core::StatusCode::Control::kGetModemStatusError == -402); | ||
| static_assert(cpp_core::StatusCode::Control::kSendBreakError == -403); | ||
| static_assert(cpp_core::StatusCode::Control::kGetStateError == -404); | ||
| static_assert(cpp_core::StatusCode::Control::kSetStateError == -405); |
Member
There was a problem hiding this comment.
Please refactor into separate test file.
Member
Author
There was a problem hiding this comment.
so, because this part of the lib is header only, there can not be any "real" tests, for the tests with static_assert to work after i put them in a separate file, the cpp-linux and cpp-windows would have to include that test file, for the tests to be executed, the tests would be executed by the compiler
Member
Author
There was a problem hiding this comment.
these static_asserts are essentially compiler checks
Mqxx
requested changes
Mar 20, 2026
Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com>
- Added static assertions to enforce constraints on category and local codes, improving safety against negative values and overflow. - Introduced a new test category, FakeCategory, to validate the computation of status codes, ensuring correct behavior across edge cases and preventing overflow. - Updated test cases to cover various scenarios, enhancing the robustness of the status code generation logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.