当前位置: 首页>>代码示例>>C++>>正文


C++ Map::Merge方法代码示例

本文整理汇总了C++中property::Map::Merge方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::Merge方法的具体用法?C++ Map::Merge怎么用?C++ Map::Merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在property::Map的用法示例。


在下文中一共展示了Map::Merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: UtcDaliPropertyMapMerge

int UtcDaliPropertyMapMerge(void)
{
  Property::Map map;
  map[ "hello" ] = 1;
  map[ "world" ] = 2;

  DALI_TEST_CHECK( map.Count() == 2 );

  // Create another map with the same keys but different values
  Property::Map map2;
  map[ "hello" ] = 3;
  map[ "world" ] = 4;

  // Merge map2 into map1, count should still be 2, map values should be from map2
  map.Merge( map2 );
  DALI_TEST_CHECK( map.Count() == 2 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );

  // Create another map with different keys
  Property::Map map3;
  map3[ "foo" ] = 5;
  map3[ "bar" ] = 6;

  // Merge map3 into map1, count should increase, existing values should match previous and new values should match map3
  map.Merge( map3 );
  DALI_TEST_CHECK( map.Count() == 4 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );

  // Create an empty map and attempt to merge, should be successful, nothing should change
  Property::Map map4;
  DALI_TEST_CHECK( map4.Empty() );
  map.Merge( map4 );
  DALI_TEST_CHECK( map4.Empty() );
  DALI_TEST_CHECK( map.Count() == 4 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );

  // Merge map into map4, map4 should be the same as map now.
  map4.Merge( map );
  DALI_TEST_CHECK( map4.Count() == 4 );
  DALI_TEST_CHECK( map4[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map4[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map4[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map4[ "bar"].Get< int >() == 6 );

  // Attempt to merge into itself, should be successful, nothing should change
  map.Merge( map );
  DALI_TEST_CHECK( map.Count() == 4 );
  DALI_TEST_CHECK( map[ "hello" ].Get< int >() == 3 );
  DALI_TEST_CHECK( map[ "world"].Get< int >() == 4 );
  DALI_TEST_CHECK( map[ "foo"].Get< int >() == 5 );
  DALI_TEST_CHECK( map[ "bar"].Get< int >() == 6 );

  END_TEST;
}
开发者ID:mettalla,项目名称:dali,代码行数:61,代码来源:utc-Dali-PropertyMap.cpp


注:本文中的property::Map::Merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。