本文整理汇总了C++中HashMap::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ HashMap::getSize方法的具体用法?C++ HashMap::getSize怎么用?C++ HashMap::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashMap
的用法示例。
在下文中一共展示了HashMap::getSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SR_NametagsDestroyImpl
ESR_ReturnCode SR_NametagsDestroyImpl(SR_Nametags* self)
{
SR_NametagsImpl* impl = (SR_NametagsImpl*) self;
LCHAR number[MAX_UINT_DIGITS+1];
ESR_ReturnCode rc;
if (impl->value != NULL)
{
size_t size, i, len;
HashMap* list = impl->value;
SR_Nametag* nametag;
CHKLOG(rc, list->getSize(list, &size));
for (i = 0; i < size; ++i)
{
CHKLOG(rc, list->getValueAtIndex(list, 0, (void **)&nametag));
CHKLOG(rc, list->removeAtIndex(list, 0));
CHKLOG(rc, nametag->destroy(nametag));
}
len = MAX_UINT_DIGITS + 1;
CHKLOG(rc, lultostr(size, (LCHAR*) &number, &len, 10));
CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("removeCount"), number));
CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("SR_NametagsDestroy")));
list->destroy(list);
impl->value = NULL;
}
CHKLOG(rc, SR_EventLogTokenPointer_BASIC(impl->eventLog, impl->logLevel, L("pointer"), self));
CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("SR_NametagsDestroy")));
impl->eventLog = NULL;
FREE(self);
return ESR_SUCCESS;
CLEANUP:
return rc;
}
示例2: SR_NametagsGetSizeImpl
ESR_ReturnCode SR_NametagsGetSizeImpl(SR_Nametags* self, size_t* result)
{
SR_NametagsImpl* impl = (SR_NametagsImpl*) self;
HashMap* nametags = impl->value;
ESR_ReturnCode rc;
CHKLOG(rc, nametags->getSize(nametags, result));
return ESR_SUCCESS;
CLEANUP:
return rc;
}
示例3: SR_NametagsLoadImpl
ESR_ReturnCode SR_NametagsLoadImpl(SR_Nametags* self, const LCHAR* filename)
{
SR_NametagsImpl* impl = (SR_NametagsImpl*) self;
ESR_ReturnCode rc;
PFile* file = NULL;
LCHAR line[256];
LCHAR* result = NULL;
LCHAR* id;
LCHAR* value;
SR_Nametag* newNametag = NULL;
SR_Nametag* oldNametag;
HashMap* nametags = impl->value;
size_t size, len, i;
LCHAR devicePath[P_PATH_MAX];
LCHAR number[MAX_UINT_DIGITS+1];
#define NAMETAGID_LENGTH 20
/* strlen("token\0") == 6 */
#define TOKEN_LENGTH 6 + NAMETAGID_LENGTH
LCHAR tokenName[TOKEN_LENGTH];
if (filename == NULL)
{
rc = ESR_INVALID_STATE;
PLogError(ESR_rc2str(rc));
goto CLEANUP;
}
size = P_PATH_MAX;
CHKLOG(rc, ESR_SessionGetLCHAR(L("cmdline.nametagPath"), devicePath, &size));
/* check if the filename has the path */
if (LSTRNCMP(filename, devicePath, LSTRLEN(devicePath)) != 0)
LSTRCAT(devicePath, filename);
else
LSTRCPY(devicePath, filename);
file = pfopen ( devicePath, L("r"));
/* CHKLOG(rc, PFileSystemCreatePFile(devicePath, ESR_TRUE, &file));
CHKLOG(rc, file->open(file, L("r")));*/
if ( file == NULL )
goto CLEANUP;
/* Flush collection */
CHKLOG(rc, nametags->getSize(nametags, &size));
for (i = 0; i < size; ++i)
{
CHKLOG(rc, nametags->getValueAtIndex(nametags, 0, (void **)&oldNametag));
CHKLOG(rc, nametags->removeAtIndex(nametags, 0));
CHKLOG(rc, oldNametag->destroy(oldNametag));
}
len = MAX_UINT_DIGITS + 1;
CHKLOG(rc, lultostr(size, number, &len, 10));
CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("removeCount"), number));
while (ESR_TRUE)
{
result = pfgets ( line, 256, file );
if (result == NULL)
break;
if (LSTRLEN(line) == 255)
{
rc = ESR_BUFFER_OVERFLOW;
PLogError(ESR_rc2str(rc));
goto CLEANUP;
}
lstrtrim(line);
/* Get the Nametag ID */
id = line;
/* Find next whitespace */
for (value = id + 1; *value != L('\0') && !LISSPACE(*value); ++value);
if (*value == L('\0'))
{
rc = ESR_INVALID_STATE;
PLogError(L("%s: Cannot find end of Nametag id"), ESR_rc2str(rc));
goto CLEANUP;
}
/* Delimit end of nametag ID */
*value = L('\0');
/* Find next non-whitespace */
for (++value; *value != L('\0') && LISSPACE(*value); ++value);
if (*value == L('\0'))
{
rc = ESR_INVALID_STATE;
PLogError(L("%s: Cannot find Nametag value"), ESR_rc2str(rc));
goto CLEANUP;
}
/* We now have both the Nametag ID and value */
len = (LSTRLEN(value)+1) * sizeof(LCHAR) ;
CHKLOG(rc, SR_NametagCreateFromValue(id, (const char*)value, len, &newNametag));
/* Add Nametag to collection */
CHKLOG(rc, impl->value->put(impl->value, id, newNametag));
if (LSTRLEN(id) > NAMETAGID_LENGTH)
{
rc = ESR_BUFFER_OVERFLOW;
PLogError(ESR_rc2str(rc));
goto CLEANUP;
}
//.........这里部分代码省略.........
示例4: SR_NametagsSaveImpl
ESR_ReturnCode SR_NametagsSaveImpl(SR_Nametags* self, const LCHAR* filename)
{
SR_NametagsImpl* impl = (SR_NametagsImpl*) self;
ESR_ReturnCode rc;
PFile* file = NULL;
size_t size, i;
HashMap* nametags = impl->value;
SR_NametagImpl* nametag;
LCHAR* id;
size_t len;
LCHAR devicePath[P_PATH_MAX];
#define NAMETAG_LENGTH 200
LCHAR nametagBuffer[NAMETAG_LENGTH];
LCHAR number[MAX_UINT_DIGITS+1];
#define NAMETAGID_LENGTH 20
/* "token\0" == 6 */
#define TOKEN_LENGTH 6 + NAMETAGID_LENGTH
LCHAR tokenName[TOKEN_LENGTH];
size_t num_written;
if (filename == NULL)
{
rc = ESR_INVALID_STATE;
PLogError(ESR_rc2str(rc));
goto CLEANUP;
}
size = P_PATH_MAX;
CHKLOG(rc, ESR_SessionGetLCHAR(L("cmdline.nametagPath"), devicePath, &size));
if (LSTRNCMP(filename, devicePath, LSTRLEN(devicePath)) != 0)
LSTRCAT(devicePath, filename);
else
LSTRCPY(devicePath, filename);
file = pfopen ( devicePath, L("w"));
/* CHKLOG(rc, PFileSystemCreatePFile(devicePath, ESR_TRUE, &file));
CHKLOG(rc, file->open(file, L("w")));*/
CHKLOG(rc, nametags->getSize(nametags, &size));
if ( file == NULL )
goto CLEANUP;
for (i = 0; i < size; ++i)
{
CHKLOG(rc, nametags->getValueAtIndex(nametags, i, (void **)&nametag));
CHKLOG(rc, nametag->Interface.getID(&nametag->Interface, &id));
if (LSTRLEN(id) + 1 + LSTRLEN(nametag->value) + 2 >= NAMETAG_LENGTH)
{
rc = ESR_BUFFER_OVERFLOW;
PLogError(ESR_rc2str(rc));
goto CLEANUP;
}
psprintf(nametagBuffer, L("%s %s\n"), id, nametag->value);
len = LSTRLEN(nametagBuffer);
/* CHKLOG(rc, file->write(file, nametagBuffer, sizeof(LCHAR), &len));*/
num_written = pfwrite ( nametagBuffer, sizeof ( LCHAR ), len, file );
if ( num_written != len )
goto CLEANUP;
if (LSTRLEN(id) > NAMETAGID_LENGTH)
{
rc = ESR_BUFFER_OVERFLOW;
PLogError(ESR_rc2str(rc));
goto CLEANUP;
}
psprintf(tokenName, L("nametag[%s]"), id);
CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, tokenName, nametag->value));
}
CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("filename"), filename));
len = MAX_UINT_DIGITS + 1;
CHKLOG(rc, lultostr(size, (LCHAR*) &number, &len, 10));
CHKLOG(rc, SR_EventLogToken_BASIC(impl->eventLog, impl->logLevel, L("saveCount"), number));
CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("SR_NametagsSave")));
pfclose (file);
return ESR_SUCCESS;
CLEANUP:
if (file != NULL)
pfclose (file);
return rc;
}
示例5:
s[len] = 0;
}
}
TEST_CASE("HashMap insert/remove testing", "[HashMap]")
{
HashMap<int> map;
map.insert("jorma", 2000);
map.insert("jarmo", 2);
map.insert("pentti", 666);
map.insert("hahahaha", -24);
map.insert("moi", 1);
REQUIRE(map.getSize() == 5);
char *str = (char*)malloc(15);
for (unsigned i = 0; i < 3500; ++i)
{
helper::gen_random(str, 10);
str[10] = '\n';
map.insert(str, i);
}
free(str);
int retVal = 0;
REQUIRE(map.find("jarmo", retVal) == true);
REQUIRE(retVal == 2);