Go
For example: Index: (ID,Type,Param,ExtType)@SpecialItem
|
// Index: (ID,Type,Param,ExtType)@SpecialItem |
|
type ItemConf_Index_SpecialItemKey struct { |
|
Id uint32 |
|
Type protoconf.FruitType |
|
Param int32 |
|
ExtType protoconf.FruitType |
|
} |
|
// FindSpecialItem finds a slice of all values of the given key. |
|
func (x *ItemConf) FindSpecialItem(key ItemConf_Index_SpecialItemKey) []*protoconf.ItemConf_Item { |
|
return x.indexSpecialItemMap[key] |
|
} |
|
|
|
// FindFirstSpecialItem finds the first value of the given key, |
|
// or nil if no value found. |
|
func (x *ItemConf) FindFirstSpecialItem(key ItemConf_Index_SpecialItemKey) *protoconf.ItemConf_Item { |
|
val := x.indexSpecialItemMap[key] |
|
if len(val) > 0 { |
|
return val[0] |
|
} |
|
return nil |
|
} |
We want a flat and easy to use APIs just like:
// FindSpecialItem finds a slice of all values of the given keys.
func (x *ItemConf) FindSpecialItem(id uint32, type protoconf.FruitType, param int32, extType protoconf.FruitType) []*protoconf.ItemConf_Item {
key := ItemConf_Index_SpecialItemKey{Id: id, Type: type , Param: param, ExtType: extType}
return x.indexSpecialItemMap[key]
}
// FindFirstSpecialItem finds the first value of the given key,
// or nil if no value found.
func (x *ItemConf) FindFirstSpecialItem(id uint32, type protoconf.FruitType, param int32, extType protoconf.FruitType) *protoconf.ItemConf_Item {
key := ItemConf_Index_SpecialItemKey{Id: id, Type: type , Param: param, ExtType: extType}
val := x.indexSpecialItemMap[key]
if len(val) > 0 {
return val[0]
}
return nil
}
C++
|
struct Index_SpecialItemKey { |
|
uint32_t id; |
|
protoconf::FruitType type; |
|
int32_t param; |
|
protoconf::FruitType ext_type; |
|
bool operator==(const Index_SpecialItemKey& other) const { |
|
return id == other.id && type == other.type && param == other.param && ext_type == other.ext_type; |
|
} |
|
}; |
|
const ItemConf::Index_SpecialItemVector* ItemConf::FindSpecialItem(const Index_SpecialItemKey& key) const { |
|
auto iter = index_special_item_map_.find(key); |
|
if (iter == index_special_item_map_.end()) { |
|
return nullptr; |
|
} |
|
return &iter->second; |
|
} |
|
|
|
const protoconf::ItemConf::Item* ItemConf::FindFirstSpecialItem(const Index_SpecialItemKey& key) const { |
|
auto conf = FindSpecialItem(key); |
|
if (conf == nullptr || conf->empty()) { |
|
return nullptr; |
|
} |
|
return conf->front(); |
|
} |
Go
For example: Index: (ID,Type,Param,ExtType)@SpecialItem
loader/test/go-tableau-loader/protoconf/loader/item_conf.pc.go
Lines 44 to 50 in d4e4775
loader/test/go-tableau-loader/protoconf/loader/item_conf.pc.go
Lines 383 to 396 in d4e4775
We want a flat and easy to use APIs just like:
C++
loader/test/cpp-tableau-loader/src/protoconf/item_conf.pc.h
Lines 131 to 139 in d4e4775
loader/test/cpp-tableau-loader/src/protoconf/item_conf.pc.cc
Lines 224 to 238 in d4e4775