Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/cpp/vim/object-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ namespace Vim
std::string mCreator;
std::string mLastChangedBy;
std::string mOwner;
std::string mChangeToken;

int mLevelIndex;
Level* mLevel;
Expand Down Expand Up @@ -1057,6 +1058,7 @@ namespace Vim
element->mCreator = GetCreator(elementIndex);
element->mLastChangedBy = GetLastChangedBy(elementIndex);
element->mOwner = GetOwner(elementIndex);
element->mChangeToken = GetChangeToken(elementIndex);
element->mLevelIndex = GetLevelIndex(elementIndex);
element->mPhaseCreatedIndex = GetPhaseCreatedIndex(elementIndex);
element->mPhaseDemolishedIndex = GetPhaseDemolishedIndex(elementIndex);
Expand Down Expand Up @@ -1085,6 +1087,7 @@ namespace Vim
bool existsCreator = mEntityTable.column_exists("string:Creator");
bool existsLastChangedBy = mEntityTable.column_exists("string:LastChangedBy");
bool existsOwner = mEntityTable.column_exists("string:Owner");
bool existsChangeToken = mEntityTable.column_exists("string:ChangeToken");
bool existsLevel = mEntityTable.column_exists("index:Vim.Level:Level");
bool existsPhaseCreated = mEntityTable.column_exists("index:Vim.Phase:PhaseCreated");
bool existsPhaseDemolished = mEntityTable.column_exists("index:Vim.Phase:PhaseDemolished");
Expand Down Expand Up @@ -1146,6 +1149,8 @@ namespace Vim

const std::vector<int>& ownerData = mEntityTable.column_exists("string:Owner") ? mEntityTable.mStringColumns["string:Owner"] : std::vector<int>();

const std::vector<int>& changeTokenData = mEntityTable.column_exists("string:ChangeToken") ? mEntityTable.mStringColumns["string:ChangeToken"] : std::vector<int>();

const std::vector<int>& levelData = mEntityTable.column_exists("index:Vim.Level:Level") ? mEntityTable.mIndexColumns["index:Vim.Level:Level"] : std::vector<int>();
const std::vector<int>& phaseCreatedData = mEntityTable.column_exists("index:Vim.Phase:PhaseCreated") ? mEntityTable.mIndexColumns["index:Vim.Phase:PhaseCreated"] : std::vector<int>();
const std::vector<int>& phaseDemolishedData = mEntityTable.column_exists("index:Vim.Phase:PhaseDemolished") ? mEntityTable.mIndexColumns["index:Vim.Phase:PhaseDemolished"] : std::vector<int>();
Expand Down Expand Up @@ -1186,6 +1191,8 @@ namespace Vim
entity.mLastChangedBy = std::string(reinterpret_cast<const char*>(mStrings[lastChangedByData[i]]));
if (existsOwner)
entity.mOwner = std::string(reinterpret_cast<const char*>(mStrings[ownerData[i]]));
if (existsChangeToken)
entity.mChangeToken = std::string(reinterpret_cast<const char*>(mStrings[changeTokenData[i]]));
entity.mLevelIndex = existsLevel ? levelData[i] : -1;
entity.mPhaseCreatedIndex = existsPhaseCreated ? phaseCreatedData[i] : -1;
entity.mPhaseDemolishedIndex = existsPhaseDemolished ? phaseDemolishedData[i] : -1;
Expand Down Expand Up @@ -1561,6 +1568,35 @@ namespace Vim
return result;
}

std::string GetChangeToken(int elementIndex)
{
if (elementIndex < 0 || elementIndex >= GetCount())
return {};

if (mEntityTable.column_exists("string:ChangeToken")) {
return std::string(reinterpret_cast<const char*>(mStrings[mEntityTable.mStringColumns["string:ChangeToken"][elementIndex]]));
}

return {};
}

std::vector<std::string>* GetAllChangeToken()
{
const auto count = GetCount();

const std::vector<int>& changeTokenData = mEntityTable.column_exists("string:ChangeToken") ? mEntityTable.mStringColumns["string:ChangeToken"] : std::vector<int>();

std::vector<std::string>* result = new std::vector<std::string>();
result->reserve(count);

for (int i = 0; i < count; ++i)
{
result->push_back(std::string(reinterpret_cast<const char*>(mStrings[changeTokenData[i]])));
}

return result;
}

int GetLevelIndex(int elementIndex)
{
if (!mEntityTable.column_exists("index:Vim.Level:Level")) {
Expand Down Expand Up @@ -3257,6 +3293,7 @@ namespace Vim
bool mIsMetric;
std::string mGuid;
int mNumSaves;
std::string mIdentity;
bool mIsLinked;
bool mIsDetached;
bool mIsWorkshared;
Expand Down Expand Up @@ -3316,6 +3353,7 @@ namespace Vim
bimDocument->mIsMetric = GetIsMetric(bimDocumentIndex);
bimDocument->mGuid = GetGuid(bimDocumentIndex);
bimDocument->mNumSaves = GetNumSaves(bimDocumentIndex);
bimDocument->mIdentity = GetIdentity(bimDocumentIndex);
bimDocument->mIsLinked = GetIsLinked(bimDocumentIndex);
bimDocument->mIsDetached = GetIsDetached(bimDocumentIndex);
bimDocument->mIsWorkshared = GetIsWorkshared(bimDocumentIndex);
Expand Down Expand Up @@ -3354,6 +3392,7 @@ namespace Vim
bool existsIsMetric = mEntityTable.column_exists("byte:IsMetric");
bool existsGuid = mEntityTable.column_exists("string:Guid");
bool existsNumSaves = mEntityTable.column_exists("int:NumSaves");
bool existsIdentity = mEntityTable.column_exists("string:Identity");
bool existsIsLinked = mEntityTable.column_exists("byte:IsLinked");
bool existsIsDetached = mEntityTable.column_exists("byte:IsDetached");
bool existsIsWorkshared = mEntityTable.column_exists("byte:IsWorkshared");
Expand Down Expand Up @@ -3403,6 +3442,8 @@ namespace Vim
memcpy(numSavesData, mEntityTable.mDataColumns["int:NumSaves"].begin(), count * sizeof(int));
}

const std::vector<int>& identityData = mEntityTable.column_exists("string:Identity") ? mEntityTable.mStringColumns["string:Identity"] : std::vector<int>();

bfast::byte* isLinkedData = new bfast::byte[count];
if (mEntityTable.column_exists("byte:IsLinked")) {
memcpy(isLinkedData, mEntityTable.mDataColumns["byte:IsLinked"].begin(), count * sizeof(bfast::byte));
Expand Down Expand Up @@ -3494,6 +3535,8 @@ namespace Vim
entity.mGuid = std::string(reinterpret_cast<const char*>(mStrings[guidData[i]]));
if (existsNumSaves)
entity.mNumSaves = numSavesData[i];
if (existsIdentity)
entity.mIdentity = std::string(reinterpret_cast<const char*>(mStrings[identityData[i]]));
if (existsIsLinked)
entity.mIsLinked = isLinkedData[i];
if (existsIsDetached)
Expand Down Expand Up @@ -3679,6 +3722,35 @@ namespace Vim
return result;
}

std::string GetIdentity(int bimDocumentIndex)
{
if (bimDocumentIndex < 0 || bimDocumentIndex >= GetCount())
return {};

if (mEntityTable.column_exists("string:Identity")) {
return std::string(reinterpret_cast<const char*>(mStrings[mEntityTable.mStringColumns["string:Identity"][bimDocumentIndex]]));
}

return {};
}

std::vector<std::string>* GetAllIdentity()
{
const auto count = GetCount();

const std::vector<int>& identityData = mEntityTable.column_exists("string:Identity") ? mEntityTable.mStringColumns["string:Identity"] : std::vector<int>();

std::vector<std::string>* result = new std::vector<std::string>();
result->reserve(count);

for (int i = 0; i < count; ++i)
{
result->push_back(std::string(reinterpret_cast<const char*>(mStrings[identityData[i]])));
}

return result;
}

bool GetIsLinked(int bimDocumentIndex)
{
if (bimDocumentIndex < 0 || bimDocumentIndex >= GetCount())
Expand Down
8 changes: 8 additions & 0 deletions src/cs/vim/Vim.Format.Core/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public DocumentBuilder(
Header = new SerializableHeader(generator, schema, versionString, optionalHeaderValues);
}

/// <summary>
/// A builder which writes the given header (for example <see cref="SerializableHeader.CreateRevisionOf"/>).
/// </summary>
public DocumentBuilder(SerializableHeader header)
{
Header = header ?? throw new ArgumentNullException(nameof(header));
}

public EntityTableBuilder GetTableBuilderOrCreate(string name)
{
if (!Tables.ContainsKey(name))
Expand Down
26 changes: 26 additions & 0 deletions src/cs/vim/Vim.Format.Core/SerializableHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ public SerializableHeader(string generator, SerializableVersion schema, string v
AddOptionalValues(values ?? new Dictionary<string, string>(), versionString))
{ }

/// <summary>
/// The header of a new revision of an existing VIM file (for example a file patched by a differential update):
/// the Id is kept, the Revision and the creation date are new (see <see cref="PersistingId"/>). The optional
/// values of the prior header are kept; <paramref name="values"/> are added or replace them.
/// </summary>
public static SerializableHeader CreateRevisionOf(
SerializableHeader prior,
string generator,
SerializableVersion schema,
IReadOnlyDictionary<string, string> values = null)
{
var d = prior.Values?.ToDictionary(kv => kv.Key, kv => kv.Value) ?? new Dictionary<string, string>();
if (values != null)
foreach (var kv in values)
d[kv.Key] = kv.Value;

return new SerializableHeader(
CurrentVimFormatVersion,
prior.Id == Guid.Empty ? Guid.NewGuid() : prior.Id,
Guid.NewGuid(),
generator,
DateTime.UtcNow,
schema ?? prior.Schema,
d);
}

/// <summary>
/// Parses the input. Throws exceptions if the input does not define a correctly formatted header.
/// </summary>
Expand Down
Loading
Loading