MCPcopy Create free account
hub / github.com/R2Northstar/NorthstarLauncher / InsertSubKey

Method InsertSubKey

primedev/shared/keyvalues.cpp:362–390  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Insert a subkey at index Input : nIndex - *pSubKey - -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

360// *pSubKey -
361//-----------------------------------------------------------------------------
362void KeyValues::InsertSubKey(int nIndex, KeyValues* pSubKey)
363{
364 // Sub key must be valid and not part of another chain
365 assert(pSubKey && pSubKey->m_pPeer == nullptr);
366
367 if (nIndex == 0)
368 {
369 pSubKey->m_pPeer = m_pSub;
370 m_pSub = pSubKey;
371 return;
372 }
373 else
374 {
375 int nCurrentIndex = 0;
376 for (KeyValues* pIter = GetFirstSubKey(); pIter != nullptr; pIter = pIter->GetNextKey())
377 {
378 ++nCurrentIndex;
379 if (nCurrentIndex == nIndex)
380 {
381 pSubKey->m_pPeer = pIter->m_pPeer;
382 pIter->m_pPeer = pSubKey;
383 return;
384 }
385 }
386 // Index is out of range if we get here
387 assert(0);
388 return;
389 }
390}
391
392//-----------------------------------------------------------------------------
393// Purpose: Checks if key contains a subkey

Callers

nothing calls this directly

Calls 1

GetNextKeyMethod · 0.80

Tested by

no test coverage detected