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

Add support for null values to AnyMap #694

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

pelliott-mathworks
Copy link
Collaborator

rapidjson supports null values but AnyMap did not. This change adds support for null values to the AnyMap class. Signed-off-by: The MathWorks, Inc. pelliott@mathworks.com

rapidjson supports null values but AnyMap did not. This change adds support for null values to the AnyMap class. Signed-off-by: The MathWorks, Inc. <pelliott@mathworks.com>
@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2022

Codecov Report

Merging #694 (ca793ee) into development (c4a8d62) will increase coverage by 0.08%.
The diff coverage is 25.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #694      +/-   ##
===============================================
+ Coverage        90.32%   90.41%   +0.08%     
===============================================
  Files              249      248       -1     
  Lines            13629    13636       +7     
===============================================
+ Hits             12311    12329      +18     
+ Misses            1318     1307      -11     
Impacted Files Coverage Δ
framework/include/cppmicroservices/AnyMap.h 52.38% <0.00%> (-20.96%) ⬇️
framework/src/bundle/BundleManifest.cpp 86.71% <100.00%> (+0.21%) ⬆️
...clarativeServices/src/manager/ReferenceManager.hpp 87.50% <0.00%> (-12.50%) ⬇️
...nfigurationAdmin/src/ConfigurationAdminPrivate.hpp 80.00% <0.00%> (-11.67%) ⬇️
framework/include/cppmicroservices/detail/Log.h 97.14% <0.00%> (-2.86%) ⬇️
.../cppmicroservices/detail/ServiceTrackerPrivate.tpp 81.69% <0.00%> (-1.17%) ⬇️
framework/src/bundle/BundleResource.cpp 95.10% <0.00%> (-0.42%) ⬇️
framework/src/util/Properties.h 100.00% <0.00%> (ø)
framework/include/cppmicroservices/ServiceEvent.h 100.00% <0.00%> (ø)
...ramework/include/cppmicroservices/BundleResource.h 100.00% <0.00%> (ø)
... and 11 more

Fix unused parameter warning in AnyMap.h NullValue struct. Signed-off-by: The MathWorks, Inc. <pelliott@mathworks.com>
* object allows us to save a null value in the AnyMap.
*/
namespace cppmicroservices {
struct NullValue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a function in the Any class to test is an Any is NullValue?

Currently, I don't think Any::Empty() and Any::ToJSON() are in alignment with this new concept of NullValue. There might also be other Any member functions which are not consistent with NullValue.

  /**
   * returns true if the Any is empty
   */
  bool Empty() const { return !_content; }


  /**
   * Returns a JSON representation for the content.
   *
   * Custom types should specialize the any_value_to_json template function for meaningful output.
   * The values of increment and indent are passed around to be able to be used for nicer
   * formatting. The code that makes use of this is in the any_value_to_json specializations for the
   * various containers.
   *
   * To get pretty output, simply pass a value greater than zero in as the first argument of ToJSON
   * and the rest of the code will take care of things.
   *
   * @param increment The amount of extra indentation to add for each level of JSON. An increment of
   *                  zero indicates no special formatting
   * @param indent    The current amount of indent to apply to the current line. 
   */
  std::string ToJSON(const uint8_t increment, const int32_t indent) const
  {
    return Empty() ? "null" : _content->ToJSON(increment, indent);
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think Empty should return true if the value is null?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that we have a user-defined type, NullValue, representing a JSON null, I think the answer is no.

I also think ToJSON returning "null" may be confusing with a ToJSON representation of JSON null

Added support to AnyMap NullValue structure to make sure functions in Any (like ToJSON and compare) work. Signed-off-by The MathWorks, Inc. <pelliott@mathworks.com>
Removed code added for debugging. Signed-off-by The MathWorks, Inc. <pelliott@mathworks.com>
Copy link
Member

@jeffdiclemente jeffdiclemente left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see test coverage for NullValue within the core framework's unit tests, i.e. within framework\test\gtest\AnyTest.cpp. Take a look at the existing tests in here for guidance on what to test. off the top of my head, testing Any::Type() for NullValue should be done.

@jeffdiclemente jeffdiclemente marked this pull request as draft May 18, 2023 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants