本文整理汇总了C++中HashMap::Put方法的典型用法代码示例。如果您正苦于以下问题:C++ HashMap::Put方法的具体用法?C++ HashMap::Put怎么用?C++ HashMap::Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashMap
的用法示例。
在下文中一共展示了HashMap::Put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char ** argv){
if (argc < 2){
printf("Argc number must more than 3");
}
if (strcmp("client", argv[1]) == 0){
ClientStart();
}else if (strcmp("server", argv[1]) == 0){
ServerStart();
}else{
HashMap* hmap = new HashMap();
char* key = "a";
char* value = "This is a";
hmap->Put(key, value, 1);
char* answer = (char*)hmap->Get(key, 1, 1);
printf("%s\n", answer);
}
//printf(strlen(NULL));
// KVServer* kvServer = new KVServer();
// kvServer->Start();
// socketTest();
// printf("Hello WOrld");
// KV* kvClient =new KV();
// testPut(kvClient, "key1", "value1");
// testPut(kvClient, "This is a Key2", "I am Value2");
// testGet(kvClient, "key1");
// testGet(kvClient, "This is a Key2");
}
示例2: _
// Archive
status_t
SecurityContext::Archive(BMessage* archive, bool deep) const
{
if (!archive)
return B_BAD_VALUE;
status_t error = B_OK;
ContextLocker _(const_cast<SecurityContext*>(this));
// users
int32 userCount = fUsers->Size();
for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) {
User* user = it.Next().value;
BMessage userArchive;
error = user->Archive(&userArchive, deep);
if (error != B_OK)
return error;
error = archive->AddMessage("users", &userArchive);
if (error != B_OK)
return error;
}
// shares
for (ShareMap::Iterator it = fShares->GetIterator(); it.HasNext();) {
Share* share = it.Next().value;
BMessage shareArchive;
error = share->Archive(&shareArchive, deep);
if (error != B_OK)
return error;
error = archive->AddMessage("shares", &shareArchive);
if (error != B_OK)
return error;
}
// permissions
// we slice them per user
BMessage* tmpUserArchives = new(std::nothrow) BMessage[userCount];
if (!tmpUserArchives)
return B_NO_MEMORY;
ArrayDeleter<BMessage> deleter(tmpUserArchives);
HashMap<HashKey32<User*>, BMessage*> userArchives;
int32 i = 0;
for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) {
User* user = it.Next().value;
error = userArchives.Put(user, tmpUserArchives + i);
if (error != B_OK)
return error;
i++;
}
// fill the per user archives
for (PermissionMap::Iterator it = fPermissions->GetIterator();
it.HasNext();) {
PermissionMap::Entry entry = it.Next();
BMessage* userArchive = userArchives.Get(entry.key.user);
error = userArchive->AddInt32(entry.key.path.GetString(),
entry.value.GetPermissions());
if (error != B_OK)
return error;
}
// put the user permissions together
BMessage permissionsArchive;
for (UserMap::Iterator it = fUsers->GetIterator(); it.HasNext();) {
User* user = it.Next().value;
error = permissionsArchive.AddMessage(user->GetName(),
userArchives.Get(user));
if (error != B_OK)
return error;
}
error = archive->AddMessage("permissions", &permissionsArchive);
if (error != B_OK)
return error;
return B_OK;
}