本文整理汇总了C++中Datum::GetTable方法的典型用法代码示例。如果您正苦于以下问题:C++ Datum::GetTable方法的具体用法?C++ Datum::GetTable怎么用?C++ Datum::GetTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datum
的用法示例。
在下文中一共展示了Datum::GetTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Adopt
void Scope::Adopt(Scope& child, const std::string& key, std::uint32_t index)
{
if (key == std::string())
throw std::exception("Key cannot be an empty string.");
child.Orphan();
child.mParent = this;
// try to find entry first in this scope
Datum* d = Find(key);
if (d != nullptr)
{
if (d->GetType() != Datum::Table)
throw std::exception("Found entry is not a table!");
if (d->IsExternal())
throw std::exception("Table is external. Cannot modify data owned by something else.");
std::uint32_t originalDatumSize = d->Size();
// if a scope is empty or not pointing to anything at the given index, we can just have it point to something else
if (originalDatumSize <= index || d->GetTable(index) == nullptr || d->GetTable(index)->mOrder.Size() == 0)
d->Set(&child, index);
// otherwise, we add in the child scope and rearrange the datum array if necessary
else
{
if (index < originalDatumSize)
{
d->SetSize(originalDatumSize + 1);
for (std::uint32_t i = originalDatumSize; i > index; --i)
{
d->Set(d->GetTable(i - 1), i);
}
}
else if (index > originalDatumSize)
{
index = originalDatumSize;
}
d->Set(&child, index);
}
}
else
{
Datum scopeDatum;
scopeDatum = &child;
std::pair<std::string, Datum> pair(key, scopeDatum);
HashMap<std::string, Datum>::Iterator iterator = mTable.Insert(pair);
mOrder.PushBack(&(*iterator));
}
}
示例2: Orphan
void Scope::Orphan()
{
std::string scopeName;
if (mParent != nullptr)
{
#ifdef DEBUG
assert(mParent->FindName(this, scopeName));
#else
mParent->FindName(this, scopeName);
#endif
Datum* d = mParent->Find(scopeName);
std::uint32_t datumSize = d->Size();
for (std::uint32_t i = 0; i < datumSize; ++i)
{
if (d->GetTable(i) == this)
{
d->Set((Scope*)nullptr, i);
break;
}
}
}
mParent = nullptr;
}
示例3: exception
Scope& Scope::AppendScope(const std::string& key)
{
if (key == std::string())
throw std::exception("Key cannot be an empty string.");
Scope* newScope = new Scope();
newScope->mParent = this;
// try to find entry first in this scope
Datum* d = Find(key);
if (d != nullptr)
{
if (d->GetType() != Datum::Table && d->GetType() != Datum::Unknown)
{
delete newScope;
throw std::exception("Found entry is not a table!");
}
if (d->IsExternal())
{
delete newScope;
throw std::exception("Table entry is external. Cannot modify data owned by something else.");
}
// a new scope gets added into this table datum
std::uint32_t datumSize = d->Size();
d->Set(newScope, datumSize);
return *d->GetTable(datumSize);
}
// if no entry is found, create new datum with this scope
Datum scopeDatum;
scopeDatum = newScope;
std::pair<std::string, Datum> pair(key, scopeDatum);
HashMap<std::string, Datum>::Iterator iterator = mTable.Insert(pair);
mOrder.PushBack(&(*iterator));
return *(iterator->second.GetTable());
}