DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
validate_flag.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 //
7 // Flag validation help functions.
8 
9 #ifndef APP_VALIDATE_FLAG_H_
10 #define APP_VALIDATE_FLAG_H_
11 
12 #include <string>
13 
14 #include "packager/base/strings/stringprintf.h"
15 
16 namespace shaka {
17 
20 void PrintError(const std::string& error_message);
21 
27 // and cannot be empty; If condition is false, then this flag should
28 // not be set.
32 template <class FlagType>
33 bool ValidateFlag(const char* flag_name,
34  const FlagType& flag_value,
35  bool condition,
36  bool optional,
37  const char* label) {
38  if (flag_value.empty()) {
39  if (!optional && condition) {
40  PrintError(
41  base::StringPrintf("--%s is required if %s.", flag_name, label));
42  return false;
43  }
44  } else if (!condition) {
45  PrintError(base::StringPrintf(
46  "--%s should be specified only if %s.", flag_name, label));
47  return false;
48  }
49  return true;
50 }
51 
52 } // namespace shaka
53 
54 #endif // APP_VALIDATE_FLAG_H_
void PrintError(const std::string &error_message)
bool ValidateFlag(const char *flag_name, const FlagType &flag_value, bool condition, bool optional, const char *label)
Definition: validate_flag.h:33