You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/01/09 15:10:18 UTC

[GitHub] [nifi-minifi-cpp] szaszm opened a new pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

szaszm opened a new pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707
 
 
   Implemented in terms of std::runtime_error
   
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] szaszm edited a comment on issue #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
szaszm edited a comment on issue #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#issuecomment-573019916
 
 
   update:
   - fix `ProcessorTests`
   - move string utilities to `StringUtils` and generalize them
   - add unit test to cover the new `StringUtils::join_pack`
   
   Moving the utilities from a private namespace to `StringUtils` means that they need to be more general IMO. I've extended them to work with any character type and do SFINAE checking on the string types. 
   
   This means quite some template code, which may not be welcome in this codebase. Suggestions are welcome.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] szaszm commented on issue #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
szaszm commented on issue #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#issuecomment-572604944
 
 
   I've added some boilerplate for string joining. I can remove it at some performance cost (extra `std::string` allocations) or additional dependency (`boost::algorithm::join`)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
arpadboda closed pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#discussion_r365213737
 
 

 ##########
 File path: libminifi/include/Exception.h
 ##########
 @@ -44,49 +43,56 @@ enum ExceptionType {
   MAX_EXCEPTION
 };
 
-// Exception String 
 static const char *ExceptionStr[MAX_EXCEPTION] = { "File Operation", "Flow File Operation", "Processor Operation", "Process Session Operation", "Process Schedule Operation", "Site2Site Protocol",
     "General Operation", "Regex Operation" };
 
-// Exception Type to String 
 inline const char *ExceptionTypeToString(ExceptionType type) {
   if (type < MAX_EXCEPTION)
     return ExceptionStr[type];
   else
     return NULL;
 }
 
-// Exception Class
-class Exception : public std::exception {
- public:
-  // Constructor
-  /*!
-   * Create a new exception
-   */
-  Exception(ExceptionType type, std::string errorMsg)
-      : _type(type),
-        _errorMsg(std::move(errorMsg)) {
-  }
+namespace detail {
+inline size_t StringLength(const char* str) { return strlen(str); }
 
-  // Destructor
-  virtual ~Exception() noexcept {
-  }
-  virtual const char * what() const noexcept {
+template<size_t L>
+constexpr size_t StringLength(const char (&str)[L]) { return L; }
 
-    _whatStr = ExceptionTypeToString(_type);
+inline size_t StringLength(const std::string& str) { return str.size(); }
 
-    _whatStr += ":" + _errorMsg;
-    return _whatStr.c_str();
-  }
+template<typename... SizeT>
+size_t sum(SizeT... ns) {
+  size_t result = 0;
+  (void)(std::initializer_list<size_t>{(
+      result += ns
+      )...});
+  return result; // (ns + ...)
+}
 
- private:
-  // Exception type
-  ExceptionType _type;
-  // Exception detailed information
-  std::string _errorMsg;
-  // Hold the what result
-  mutable std::string _whatStr;
+template<typename... Strs>
+std::string StringJoin(Strs&&... strs) {
 
 Review comment:
   moved to StringUtils in dbc0033

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] szaszm commented on issue #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
szaszm commented on issue #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#issuecomment-573019916
 
 
   update:
   - fix `ProcessorTests`
   - move string utilities to `StringUtils` and generalize them
   - add unit test to cover the new `StringUtils::join_pack`
   Moving the utilities from a private namespace to `StringUtils` means that they need to be more general IMO. I've extended them to work with any character type and do SFINAE checking on the string types. 
   This means quite some template code, which may not be welcome in this codebase. Suggestions are welcome.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] nghiaxlee commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
nghiaxlee commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#discussion_r364824744
 
 

 ##########
 File path: libminifi/include/Exception.h
 ##########
 @@ -44,49 +43,56 @@ enum ExceptionType {
   MAX_EXCEPTION
 };
 
-// Exception String 
 static const char *ExceptionStr[MAX_EXCEPTION] = { "File Operation", "Flow File Operation", "Processor Operation", "Process Session Operation", "Process Schedule Operation", "Site2Site Protocol",
     "General Operation", "Regex Operation" };
 
-// Exception Type to String 
 inline const char *ExceptionTypeToString(ExceptionType type) {
   if (type < MAX_EXCEPTION)
     return ExceptionStr[type];
   else
     return NULL;
 }
 
-// Exception Class
-class Exception : public std::exception {
- public:
-  // Constructor
-  /*!
-   * Create a new exception
-   */
-  Exception(ExceptionType type, std::string errorMsg)
-      : _type(type),
-        _errorMsg(std::move(errorMsg)) {
-  }
+namespace detail {
+inline size_t StringLength(const char* str) { return strlen(str); }
 
-  // Destructor
-  virtual ~Exception() noexcept {
-  }
-  virtual const char * what() const noexcept {
+template<size_t L>
+constexpr size_t StringLength(const char (&str)[L]) { return L; }
 
-    _whatStr = ExceptionTypeToString(_type);
+inline size_t StringLength(const std::string& str) { return str.size(); }
 
-    _whatStr += ":" + _errorMsg;
-    return _whatStr.c_str();
-  }
+template<typename... SizeT>
+size_t sum(SizeT... ns) {
+  size_t result = 0;
+  (void)(std::initializer_list<size_t>{(
+      result += ns
+      )...});
+  return result; // (ns + ...)
+}
 
- private:
-  // Exception type
-  ExceptionType _type;
-  // Exception detailed information
-  std::string _errorMsg;
-  // Hold the what result
-  mutable std::string _whatStr;
+template<typename... Strs>
+std::string StringJoin(Strs&&... strs) {
 
 Review comment:
   I think this should be moved to our StringUtils if we haven't had this feature yet.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#discussion_r364854644
 
 

 ##########
 File path: libminifi/include/Exception.h
 ##########
 @@ -44,49 +43,56 @@ enum ExceptionType {
   MAX_EXCEPTION
 };
 
-// Exception String 
 static const char *ExceptionStr[MAX_EXCEPTION] = { "File Operation", "Flow File Operation", "Processor Operation", "Process Session Operation", "Process Schedule Operation", "Site2Site Protocol",
     "General Operation", "Regex Operation" };
 
-// Exception Type to String 
 inline const char *ExceptionTypeToString(ExceptionType type) {
   if (type < MAX_EXCEPTION)
     return ExceptionStr[type];
   else
     return NULL;
 }
 
-// Exception Class
-class Exception : public std::exception {
- public:
-  // Constructor
-  /*!
-   * Create a new exception
-   */
-  Exception(ExceptionType type, std::string errorMsg)
-      : _type(type),
-        _errorMsg(std::move(errorMsg)) {
-  }
+namespace detail {
+inline size_t StringLength(const char* str) { return strlen(str); }
 
-  // Destructor
-  virtual ~Exception() noexcept {
-  }
-  virtual const char * what() const noexcept {
+template<size_t L>
+constexpr size_t StringLength(const char (&str)[L]) { return L; }
 
 Review comment:
   bug here: L is the size of the array, not the string inside. I'll change it to `max(L-1, 0)` and leave the case of early null termination unhandled if the functionality is not already present in StringUtils.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#discussion_r364825410
 
 

 ##########
 File path: libminifi/include/Exception.h
 ##########
 @@ -44,49 +43,56 @@ enum ExceptionType {
   MAX_EXCEPTION
 };
 
-// Exception String 
 static const char *ExceptionStr[MAX_EXCEPTION] = { "File Operation", "Flow File Operation", "Processor Operation", "Process Session Operation", "Process Schedule Operation", "Site2Site Protocol",
     "General Operation", "Regex Operation" };
 
-// Exception Type to String 
 inline const char *ExceptionTypeToString(ExceptionType type) {
   if (type < MAX_EXCEPTION)
     return ExceptionStr[type];
   else
     return NULL;
 }
 
-// Exception Class
-class Exception : public std::exception {
- public:
-  // Constructor
-  /*!
-   * Create a new exception
-   */
-  Exception(ExceptionType type, std::string errorMsg)
-      : _type(type),
-        _errorMsg(std::move(errorMsg)) {
-  }
+namespace detail {
+inline size_t StringLength(const char* str) { return strlen(str); }
 
-  // Destructor
-  virtual ~Exception() noexcept {
-  }
-  virtual const char * what() const noexcept {
+template<size_t L>
+constexpr size_t StringLength(const char (&str)[L]) { return L; }
 
-    _whatStr = ExceptionTypeToString(_type);
+inline size_t StringLength(const std::string& str) { return str.size(); }
 
-    _whatStr += ":" + _errorMsg;
-    return _whatStr.c_str();
-  }
+template<typename... SizeT>
+size_t sum(SizeT... ns) {
+  size_t result = 0;
+  (void)(std::initializer_list<size_t>{(
+      result += ns
+      )...});
+  return result; // (ns + ...)
+}
 
- private:
-  // Exception type
-  ExceptionType _type;
-  // Exception detailed information
-  std::string _errorMsg;
-  // Hold the what result
-  mutable std::string _whatStr;
+template<typename... Strs>
+std::string StringJoin(Strs&&... strs) {
 
 Review comment:
   Good point, we do have a join there.
   Might don't have such an override, but better extending that. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #707: MINIFICPP-1117 - minifi::Exception is now nothrow copyable
URL: https://github.com/apache/nifi-minifi-cpp/pull/707#discussion_r364825410
 
 

 ##########
 File path: libminifi/include/Exception.h
 ##########
 @@ -44,49 +43,56 @@ enum ExceptionType {
   MAX_EXCEPTION
 };
 
-// Exception String 
 static const char *ExceptionStr[MAX_EXCEPTION] = { "File Operation", "Flow File Operation", "Processor Operation", "Process Session Operation", "Process Schedule Operation", "Site2Site Protocol",
     "General Operation", "Regex Operation" };
 
-// Exception Type to String 
 inline const char *ExceptionTypeToString(ExceptionType type) {
   if (type < MAX_EXCEPTION)
     return ExceptionStr[type];
   else
     return NULL;
 }
 
-// Exception Class
-class Exception : public std::exception {
- public:
-  // Constructor
-  /*!
-   * Create a new exception
-   */
-  Exception(ExceptionType type, std::string errorMsg)
-      : _type(type),
-        _errorMsg(std::move(errorMsg)) {
-  }
+namespace detail {
+inline size_t StringLength(const char* str) { return strlen(str); }
 
-  // Destructor
-  virtual ~Exception() noexcept {
-  }
-  virtual const char * what() const noexcept {
+template<size_t L>
+constexpr size_t StringLength(const char (&str)[L]) { return L; }
 
-    _whatStr = ExceptionTypeToString(_type);
+inline size_t StringLength(const std::string& str) { return str.size(); }
 
-    _whatStr += ":" + _errorMsg;
-    return _whatStr.c_str();
-  }
+template<typename... SizeT>
+size_t sum(SizeT... ns) {
+  size_t result = 0;
+  (void)(std::initializer_list<size_t>{(
+      result += ns
+      )...});
+  return result; // (ns + ...)
+}
 
- private:
-  // Exception type
-  ExceptionType _type;
-  // Exception detailed information
-  std::string _errorMsg;
-  // Hold the what result
-  mutable std::string _whatStr;
+template<typename... Strs>
+std::string StringJoin(Strs&&... strs) {
 
 Review comment:
   Good point, we do have a join there.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services