#define DALI_PROPERTY_MAP_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// EXTERNAL INCLUDES
-#include <string>
-#include <sstream>
#include <initializer_list>
+#include <sstream>
+#include <string>
+#include <string_view>
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/object/property.h>
#include <dali/public-api/object/property-key.h>
#include <dali/public-api/object/property-value.h>
+#include <dali/public-api/object/property.h>
namespace Dali
{
* @{
*/
-typedef std::pair< Property::Key, Property::Value > KeyValuePair;
-typedef std::pair<std::string, Property::Value> StringValuePair;
+using KeyValuePair = std::pair<Property::Key, Property::Value>;
+using StringValuePair = std::pair<std::string, Property::Value>;
/**
* @brief A Map of property values, the key type could be String or Property::Index.
class DALI_CORE_API Property::Map
{
public:
-
- typedef std::size_t SizeType;
+ using SizeType = std::size_t;
/**
* @brief Default constructor.
* @SINCE_1_4.17
* @param[in] values An initializer_list of pairs of index and value.
*/
- Map( const std::initializer_list< KeyValuePair >& values );
+ Map(const std::initializer_list<KeyValuePair>& values);
/**
* @brief Copy constructor.
* @SINCE_1_0.0
* @param[in] other The Map to copy from
*/
- Map( const Map& other );
+ Map(const Map& other);
/**
* @brief Move constructor.
* @param[in] other The Map to move from
* @note After the @a other array is used, it becomes invalid and is no longer usable.
*/
- Map( Map&& other );
+ Map(Map&& other);
/**
* @brief Non-virtual destructor.
* @param[in] key The key to insert
* @param[in] value The value to insert
*/
- void Insert( const char* key, const Value& value );
-
- /**
- * @brief Inserts the key-value pair in the Map, with the key type as string.
- *
- * Does not check for duplicates.
- * @SINCE_1_0.0
- * @param[in] key The key to insert
- * @param[in] value The value to insert
- */
- void Insert( const std::string& key, const Value& value );
+ void Insert(std::string key, Value value);
/**
* @brief Inserts the key-value pair in the Map, with the key type as index.
* @param[in] key The key to insert
* @param[in] value The value to insert
*/
- void Insert( Property::Index key, const Value& value );
-
-
- /**
- * @brief Inserts the key-value pair in the Map, with the key type as string.
- *
- * Does not check for duplicates
- * @SINCE_1_2.5
- * @param key to insert
- * @param value to insert
- * @return a reference to this object
- */
- inline Property::Map& Add( const char* key, const Value& value )
- {
- Insert(key, value);
- return *this;
- }
+ void Insert(Property::Index key, Value value);
/**
* @brief Inserts the key-value pair in the Map, with the key type as string.
* @param value to insert
* @return a reference to this object
*/
- inline Property::Map& Add( const std::string& key, const Value& value )
+ Property::Map& Add(std::string key, Value value)
{
- Insert(key, value);
+ Insert(std::move(key), std::move(value));
return *this;
}
-
/**
* @brief Inserts the key-value pair in the Map, with the key type as index.
*
* @param value to insert
* @return a reference to this object
*/
- inline Property::Map& Add( Property::Index key, const Value& value )
+ Property::Map& Add(Property::Index key, Value value)
{
- Insert(key, value);
+ Insert(key, std::move(value));
return *this;
}
*
* @note Will assert if position >= Count()
*/
- Value& GetValue( SizeType position ) const;
+ Value& GetValue(SizeType position) const;
/**
* DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
*
* @note Will assert if position >= Count()
*/
- const std::string& GetKey( SizeType position ) const DALI_DEPRECATED_API;
+ const std::string& GetKey(SizeType position) const DALI_DEPRECATED_API;
/**
* @brief Retrieve the key at the specified position.
*
* @note Will assert if position >= Count()
*/
- Key GetKeyAt( SizeType position ) const;
+ Key GetKeyAt(SizeType position) const;
/**
* DEPRECATED_1_1.39 Position based retrieval is no longer supported after extending the key type to both Index and String.
*
* @note Will assert if position >= Count() or key at position is an index key.
*/
- StringValuePair& GetPair( SizeType position ) const DALI_DEPRECATED_API;
+ StringValuePair& GetPair(SizeType position) const DALI_DEPRECATED_API;
/**
* @brief Retrieve the key & the value at the specified position.
*
* @note Will assert if position >= Count()
*/
- KeyValuePair GetKeyValue( SizeType position ) const;
-
- /**
- * @brief Finds the value for the specified key if it exists.
- *
- * @SINCE_1_0.0
- * @param[in] key The key to find
- *
- * @return A const pointer to the value if it exists, NULL otherwise
- */
- Value* Find( const char* key ) const;
+ KeyValuePair GetKeyValue(SizeType position) const;
/**
* @brief Finds the value for the specified key if it exists.
*
* @return A const pointer to the value if it exists, NULL otherwise
*/
- Value* Find( const std::string& key ) const;
+ Value* Find(std::string_view key) const;
/**
* @brief Finds the value for the specified key if it exists.
*
* @return A const pointer to the value if it exists, NULL otherwise
*/
- Value* Find( Property::Index key ) const;
+ Value* Find(Property::Index key) const;
/**
* @brief Finds the value for the specified keys if either exist.
*
* @return A const pointer to the value if it exists, NULL otherwise
*/
- Value* Find( Property::Index indexKey, const std::string& stringKey ) const;
+ Value* Find(Property::Index indexKey, std::string_view stringKey) const;
/**
* @brief Finds the value for the specified key if it exists and its type is type.
*
* @return A const pointer to the value if it exists, NULL otherwise
*/
- Value* Find( const std::string& key, Property::Type type ) const;
+ Value* Find(std::string_view key, Property::Type type) const;
/**
* @brief Finds the value for the specified key if it exists and its type is type.
*
* @return A const pointer to the value if it exists, NULL otherwise
*/
- Value* Find( Property::Index key, Property::Type type ) const;
+ Value* Find(Property::Index key, Property::Type type) const;
/**
* @brief Clears the map.
* @SINCE_1_0.0
* @param[in] from The map to merge from
*/
- void Merge( const Map& from );
+ void Merge(const Map& from);
/**
* @brief Const operator to access element with the specified string key.
*
* @note Will assert if invalid-key is given.
*/
- const Value& operator[]( const std::string& key ) const;
+ const Value& operator[](std::string_view key) const;
/**
* @brief Operator to access the element with the specified string key.
*
* @note If an element with the key does not exist, then it is created.
*/
- Value& operator[]( const std::string& key );
+ Value& operator[](std::string_view key);
/**
* @brief Const operator to access element with the specified index key.
*
* @note Will assert if invalid-key is given.
*/
- const Value& operator[]( Property::Index key ) const;
+ const Value& operator[](Property::Index key) const;
/**
* @brief Operator to access the element with the specified index key.
*
* @note If an element with the key does not exist, then it is created.
*/
- Value& operator[]( Property::Index key );
+ Value& operator[](Property::Index key);
/**
* @brief Assignment operator.
*
* @return The copied map
*/
- Map& operator=( const Map& other );
+ Map& operator=(const Map& other);
/**
* @brief Move assignment operator.
*
* @note The other array is an r-value so becomes invalid and is no longer usable.
*/
- Map& operator=( Map&& other );
+ Map& operator=(Map&& other);
/**
* @brief Output to stream.
* @SINCE_1_1.28
*/
- friend DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
+ friend DALI_CORE_API std::ostream& operator<<(std::ostream& stream, const Property::Map& map);
private:
- struct DALI_INTERNAL Impl; ///< Private data
- Impl* mImpl; ///< Pointer to private data
+ struct DALI_INTERNAL Impl; ///< Private data
+ Impl* mImpl; ///< Pointer to private data
};
/**
* @param[in] map The map to insert
* @return The output stream operator
*/
-DALI_CORE_API std::ostream& operator<<( std::ostream& stream, const Property::Map& map );
+DALI_CORE_API std::ostream& operator<<(std::ostream& stream, const Property::Map& map);
/**
* @}