layers: Add parameter_validation namespace

Add parameter_validation namespace for utility functions.  Namespace will
be extended to include core layer functions in a future update.

Change-Id: I0929f5caacbf3e1b4509f051ea020566cce44e3e
diff --git a/layers/parameter_validation_utils.h b/layers/parameter_validation_utils.h
index 5667351..29182bf 100644
--- a/layers/parameter_validation_utils.h
+++ b/layers/parameter_validation_utils.h
@@ -29,15 +29,15 @@
 #include "vk_enum_string_helper.h"
 #include "vk_layer_logging.h"
 
-namespace {
+namespace parameter_validation {
+
 struct GenericHeader {
     VkStructureType sType;
     const void *pNext;
 };
-}
 
 // Layer name string to be logged with validation messages.
-const char ParameterValidationName[] = "ParameterValidation";
+const char LayerName[] = "ParameterValidation";
 
 // String returned by string_VkStructureType for an unrecognized type.
 const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType";
@@ -78,45 +78,8 @@
     bool skipCall = false;
 
     if (value == NULL) {
-        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, parameterName);
-    }
-
-    return skipCall;
-}
-
-/**
- * Validate pointer to array count and pointer to array.
- *
- * Verify that required count and array parameters are not NULL.  If count
- * is not NULL and its value is not optional, verify that it is not 0.  If the
- * array parameter is NULL, and it is not optional, verify that count is 0.
- * The array parameter will typically be optional for this case (where count is
- * a pointer), allowing the caller to retrieve the available count.
- *
- * @param report_data debug_report_data object for routing validation messages.
- * @param apiName Name of API call being validated.
- * @param countName Name of count parameter.
- * @param arrayName Name of array parameter.
- * @param count Pointer to the number of elements in the array.
- * @param array Array to validate.
- * @param countPtrRequired The 'count' parameter may not be NULL when true.
- * @param countValueRequired The '*count' value may not be 0 when true.
- * @param arrayRequired The 'array' parameter may not be NULL when true.
- * @return Boolean value indicating that the call should be skipped.
- */
-template <typename T>
-bool validate_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName,
-                    const T *count, const void *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired) {
-    bool skipCall = false;
-
-    if (count == NULL) {
-        if (countPtrRequired) {
-            skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, countName);
-        }
-    } else {
-        skipCall |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired);
+        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: required parameter %s specified as NULL", apiName, parameterName);
     }
 
     return skipCall;
@@ -146,14 +109,52 @@
 
     // Count parameters not tagged as optional cannot be 0
     if ((count == 0) && countRequired) {
-        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: parameter %s must be greater than 0", apiName, countName);
+        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: parameter %s must be greater than 0", apiName, countName);
     }
 
     // Array parameters not tagged as optional cannot be NULL, unless the count is 0
     if ((array == NULL) && arrayRequired && (count != 0)) {
-        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, arrayName);
+        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: required parameter %s specified as NULL", apiName, arrayName);
+    }
+
+    return skipCall;
+}
+
+/**
+* Validate pointer to array count and pointer to array.
+*
+* Verify that required count and array parameters are not NULL.  If count
+* is not NULL and its value is not optional, verify that it is not 0.  If the
+* array parameter is NULL, and it is not optional, verify that count is 0.
+* The array parameter will typically be optional for this case (where count is
+* a pointer), allowing the caller to retrieve the available count.
+*
+* @param report_data debug_report_data object for routing validation messages.
+* @param apiName Name of API call being validated.
+* @param countName Name of count parameter.
+* @param arrayName Name of array parameter.
+* @param count Pointer to the number of elements in the array.
+* @param array Array to validate.
+* @param countPtrRequired The 'count' parameter may not be NULL when true.
+* @param countValueRequired The '*count' value may not be 0 when true.
+* @param arrayRequired The 'array' parameter may not be NULL when true.
+* @return Boolean value indicating that the call should be skipped.
+*/
+template <typename T>
+bool validate_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName,
+    const T *count, const void *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired) {
+    bool skipCall = false;
+
+    if (count == NULL) {
+        if (countPtrRequired) {
+            skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
+                LayerName, "%s: required parameter %s specified as NULL", apiName, countName);
+        }
+    }
+    else {
+        skipCall |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired);
     }
 
     return skipCall;
@@ -183,11 +184,11 @@
     if (value == NULL) {
         if (required) {
             skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, parameterName);
+                                LayerName, "%s: required parameter %s specified as NULL", apiName, parameterName);
         }
     } else if (value->sType != sType) {
-        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: parameter %s->sType must be %s", apiName, parameterName, sTypeName);
+        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: parameter %s->sType must be %s", apiName, parameterName, sTypeName);
     }
 
     return skipCall;
@@ -223,7 +224,7 @@
     if (count == NULL) {
         if (countPtrRequired) {
             skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, countName);
+                                LayerName, "%s: required parameter %s specified as NULL", apiName, countName);
         }
     } else {
         skipCall |= validate_struct_type_array(report_data, apiName, countName, arrayName, sTypeName, (*count), array, sType,
@@ -264,9 +265,8 @@
         // Verify that all structs in the array have the correct type
         for (uint32_t i = 0; i < count; ++i) {
             if (array[i].sType != sType) {
-                skipCall |=
-                    log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: parameter %s[%d].sType must be %s", apiName, arrayName, i, sTypeName);
+                skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
+                                    LayerName, "%s: parameter %s[%d].sType must be %s", apiName, arrayName, i, sTypeName);
             }
         }
     }
@@ -290,9 +290,8 @@
     bool skip_call = false;
 
     if (value == VK_NULL_HANDLE) {
-        skip_call |=
-            log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                    ParameterValidationName, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name, parameter_name);
+        skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                             "%s: required parameter %s specified as VK_NULL_HANDLE", api_name, parameter_name);
     }
 
     return skip_call;
@@ -331,9 +330,9 @@
         // Verify that no handles in the array are VK_NULL_HANDLE
         for (uint32_t i = 0; i < count; ++i) {
             if (array[i] == VK_NULL_HANDLE) {
-                skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                     ParameterValidationName, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name,
-                                     array_name, i);
+                skip_call |=
+                    log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name, array_name, i);
             }
         }
     }
@@ -369,9 +368,8 @@
         // Verify that strings in the array are not NULL
         for (uint32_t i = 0; i < count; ++i) {
             if (array[i] == NULL) {
-                skipCall |=
-                    log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: required parameter %s[%d] specified as NULL", apiName, arrayName, i);
+                skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
+                                    LayerName, "%s: required parameter %s[%d] specified as NULL", apiName, arrayName, i);
             }
         }
     }
@@ -403,7 +401,7 @@
     if (next != NULL) {
         if (allowedTypeCount == 0) {
             skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                ParameterValidationName, "%s: value of %s must be NULL", apiName, parameterName);
+                                LayerName, "%s: value of %s must be NULL", apiName, parameterName);
         } else {
             const VkStructureType *start = allowedTypes;
             const VkStructureType *end = allowedTypes + allowedTypeCount;
@@ -415,14 +413,12 @@
 
                     if (typeName == UnsupportedStructureTypeString) {
                         skipCall |= log_msg(
-                            report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName,
+                            report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
                             "%s: %s chain includes a structure with unexpected VkStructureType (%d); Allowed structures are [%s]",
                             apiName, parameterName, current->sType, allowedStructNames);
                     } else {
                         skipCall |= log_msg(
-                            report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName,
+                            report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
                             "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are [%s]",
                             apiName, parameterName, typeName.c_str(), allowedStructNames);
                     }
@@ -451,9 +447,8 @@
     bool skipCall = false;
 
     if ((value != VK_TRUE) && (value != VK_FALSE)) {
-        skipCall |=
-            log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                    ParameterValidationName, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName, parameterName, value);
+        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName, parameterName, value);
     }
 
     return skipCall;
@@ -484,11 +479,10 @@
     bool skipCall = false;
 
     if (((value < begin) || (value > end)) && !is_extension_added_token(value)) {
-        skipCall |=
-            log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                    ParameterValidationName, "%s: value of %s (%d) does not fall within the begin..end range of the core %s "
-                                             "enumeration tokens and is not an extension added token",
-                    apiName, parameterName, value, enumName);
+        skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                            "%s: value of %s (%d) does not fall within the begin..end range of the core %s "
+                            "enumeration tokens and is not an extension added token",
+                            apiName, parameterName, value, enumName);
     }
 
     return skipCall;
@@ -529,9 +523,8 @@
         for (uint32_t i = 0; i < count; ++i) {
             if (((array[i] < begin) || (array[i] > end)) && !is_extension_added_token(array[i])) {
                 skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                    ParameterValidationName,
-                                    "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
-                                    "enumeration tokens and is not an extension added token",
+                                    LayerName, "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
+                                               "enumeration tokens and is not an extension added token",
                                     apiName, arrayName, i, array[i], enumName);
             }
         }
@@ -557,8 +550,8 @@
     bool skip_call = false;
 
     if (value != 0) {
-        skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                             ParameterValidationName, "%s: parameter %s must be 0", api_name, parameter_name);
+        skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                             "%s: parameter %s must be 0", api_name, parameter_name);
     }
 
     return skip_call;
@@ -586,12 +579,12 @@
     if (value == 0) {
         if (flags_required) {
             skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                                 ParameterValidationName, "%s: value of %s must not be 0", api_name, parameter_name);
+                                 LayerName, "%s: value of %s must not be 0", api_name, parameter_name);
         }
     } else if ((value & (~all_flags)) != 0) {
-        skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                             ParameterValidationName, "%s: value of %s contains flag bits that are not recognized members of %s",
-                             api_name, parameter_name, flag_bits_name);
+        skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                             "%s: value of %s contains flag bits that are not recognized members of %s", api_name, parameter_name,
+                             flag_bits_name);
     }
 
     return skip_call;
@@ -630,13 +623,12 @@
                 // elements in the array are allowed be 0
                 if (array_required) {
                     skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
-                                         1, ParameterValidationName, "%s: value of %s[%d] must not be 0", api_name, array_name, i);
+                                         1, LayerName, "%s: value of %s[%d] must not be 0", api_name, array_name, i);
                 }
             } else if ((array[i] & (~all_flags)) != 0) {
-                skip_call |=
-                    log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                            ParameterValidationName, "%s: value of %s[%d] contains flag bits that are not recognized members of %s",
-                            api_name, array_name, i, flag_bits_name);
+                skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
+                                     LayerName, "%s: value of %s[%d] contains flag bits that are not recognized members of %s",
+                                     api_name, array_name, i, flag_bits_name);
             }
         }
     }
@@ -706,14 +698,16 @@
 
         if (resultName == UnsupportedResultString) {
             // Unrecognized result code
-            log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                    ParameterValidationName, "%s: returned a result code indicating that an error has occurred", apiName);
+            log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                    "%s: returned a result code indicating that an error has occurred", apiName);
         } else {
             std::string resultDesc = get_result_description(result);
-            log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
-                    ParameterValidationName, "%s: returned %s, indicating that %s", apiName, resultName.c_str(), resultDesc.c_str());
+            log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
+                    "%s: returned %s, indicating that %s", apiName, resultName.c_str(), resultDesc.c_str());
         }
     }
 }
 
+} // namespace parameter_validation
+
 #endif // PARAMETER_VALIDATION_UTILS_H