diff options
author | Alex Vakulenko <avakulenko@google.com> | 2015-10-12 15:21:28 -0700 |
---|---|---|
committer | Alex Vakulenko <avakulenko@google.com> | 2015-10-13 16:10:03 -0700 |
commit | 9ed0cab99f18acb3570a35e9408f24355f6b8324 (patch) | |
tree | 60e3b4c2822b812b3218489a9a6d835df1e8ca6e /brillo/variant_dictionary.h | |
parent | eabfe23a51c91a103042793ac2d5c28170994e1f (diff) | |
download | platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.tar.gz platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.tar.bz2 platform_external_libbrillo-9ed0cab99f18acb3570a35e9408f24355f6b8324.zip |
Move chromeos symbols into brillo namespace
And move the include files into "brillo" directory instead of "chromeos"
BUG: 24872993
TEST=built aosp and brillo and unit tests pass on dragonoboard
Change-Id: Ieb979d1ebd3152921d36cd15acbd6247f02aae69
Diffstat (limited to 'brillo/variant_dictionary.h')
-rw-r--r-- | brillo/variant_dictionary.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/brillo/variant_dictionary.h b/brillo/variant_dictionary.h new file mode 100644 index 0000000..c934455 --- /dev/null +++ b/brillo/variant_dictionary.h @@ -0,0 +1,33 @@ +// Copyright 2014 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LIBCHROMEOS_BRILLO_VARIANT_DICTIONARY_H_ +#define LIBCHROMEOS_BRILLO_VARIANT_DICTIONARY_H_ + +#include <map> +#include <string> + +#include <brillo/any.h> +#include <brillo/brillo_export.h> + +namespace brillo { + +using VariantDictionary = std::map<std::string, brillo::Any>; + +// GetVariantValueOrDefault tries to retrieve the named key from the dictionary +// and convert it to the type T. If the value does not exist, or the type +// conversion fails, the default value of type T is returned. +template<typename T> +const T GetVariantValueOrDefault(const VariantDictionary& dictionary, + const std::string& key) { + VariantDictionary::const_iterator it = dictionary.find(key); + if (it == dictionary.end()) { + return T(); + } + return it->second.TryGet<T>(); +} + +} // namespace brillo + +#endif // LIBCHROMEOS_BRILLO_VARIANT_DICTIONARY_H_ |