]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#549] not strictly related: return enum from Element::getType()
authorAndrei Pavel <andrei@isc.org>
Wed, 5 Apr 2023 13:07:38 +0000 (16:07 +0300)
committerAndrei Pavel <andrei@isc.org>
Wed, 19 Apr 2023 20:56:01 +0000 (23:56 +0300)
So you don't have to cast it each time it's used.

src/lib/cc/data.cc
src/lib/cc/data.h
src/lib/cc/stamped_value.cc

index 20c201548415990c45f6f228ad566f90763499a8..2df39abf4875606641f28492499f59be9f377529 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -229,9 +229,9 @@ operator<(Element const& a, Element const& b) {
         return b.boolValue() || !a.boolValue();
     case Element::string:
         return std::strcmp(a.stringValue().c_str(), b.stringValue().c_str()) < 0;
+    default:
+        isc_throw(BadValue, "cannot compare Elements of type " << to_string(a.getType()));
     }
-    isc_throw(BadValue, "cannot compare Elements of type " <<
-                            std::to_string(a.getType()));
 }
 
 //
index 7cb23807138d627f6d4c9a2d3b74581bf74bfb94..916ad3f10676e8cfbb21a97a1bc2f8707ca0ca53 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -126,11 +126,15 @@ public:
         return (position);
     }
 
+    // any is a special type used in list specifications, specifying
+    // that the elements can be of any type
+    enum types { integer, real, boolean, null, string, list, map, any };
+
 private:
     // technically the type could be omitted; is it useful?
     // should we remove it or replace it with a pure virtual
     // function getType?
-    int type_;
+    types type_;
 
     /// @brief Position of the element in the configuration string.
     Position position_;
@@ -143,21 +147,17 @@ protected:
     /// @param pos Structure holding position of the value of the data element.
     /// It comprises the line number and the position within this line. The values
     /// held in this structure are used for error logging purposes.
-    Element(int t, const Position& pos = ZERO_POSITION())
+    Element(types t, const Position& pos = ZERO_POSITION())
         : type_(t), position_(pos) {
     }
 
 
 public:
-
-    // any is a special type used in list specifications, specifying
-    // that the elements can be of any type
-    enum types { integer, real, boolean, null, string, list, map, any };
     // base class; make dtor virtual
     virtual ~Element() {};
 
     /// @return the type of this element
-    int getType() const { return (type_); }
+    types getType() const { return (type_); }
 
     /// @brief Returns position where the data element's value starts in a
     /// configuration string.
index b6554ea829b401bb1304ebf9069bb844e9285391..077c688584246fc77b70bc4ec1d986113d71a459 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -169,7 +169,7 @@ StampedValue::validateConstruct() const {
         (value_->getType() != Element::real)) {
         isc_throw(TypeError, "StampedValue: provided value of the '"
                   << name_ << "' parameter has invalid type: "
-                  << Element::typeToName(static_cast<Element::types>(value_->getType())));
+                  << Element::typeToName(value_->getType()));
     }
 }
 
@@ -184,7 +184,7 @@ StampedValue::validateAccess(Element::types type) const {
         isc_throw(TypeError, "StampedValue: attempt to access a '"
                   << name_ << "' parameter as " << Element::typeToName(type)
                   << ", but this parameter has "
-                  << Element::typeToName(static_cast<Element::types>(value_->getType()))
+                  << Element::typeToName(value_->getType())
                   << " type");
     }
 }