Skip to content

Commit

Permalink
#5623: Move ComparisonResult to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 24, 2021
1 parent 63444dc commit 9827b56
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 83 deletions.
98 changes: 98 additions & 0 deletions libs/scene/merge/ComparisonResult.h
@@ -0,0 +1,98 @@
#pragma once

#include <memory>
#include <list>
#include "imap.h"
#include "inode.h"

namespace scene
{

namespace merge
{

class ComparisonResult
{
public:
using Ptr = std::shared_ptr<ComparisonResult>;

private:
// This result instance will hold references to the root nodes of the compared graph
// to ensure the graph stays alive as long as the result
scene::IMapRootNodePtr _sourceRoot;
scene::IMapRootNodePtr _baseRoot;

public:
// Represents a matching node pair
struct Match
{
std::string fingerPrint;
scene::INodePtr sourceNode;
scene::INodePtr baseNode;
};

struct KeyValueDifference
{
std::string key;
std::string value;

enum class Type
{
KeyValueAdded, // key is present on the source entity, but not on the base
KeyValueRemoved, // key is present on the base entity, but not on the source
KeyValueChanged, // key present on both, but value is different
};

Type type;
};

struct PrimitiveDifference
{
std::string fingerprint;
scene::INodePtr node;

enum class Type
{
PrimitiveAdded, // child is present on the source entity, but not on the base
PrimitiveRemoved, // child is present on the base entity, but not on the source
};

Type type;
};

struct EntityDifference
{
std::string fingerprint;
scene::INodePtr node;
std::string entityName;

enum class Type
{
EntityMissingInSource,
EntityMissingInBase,
EntityPresentButDifferent,
};

Type type;

std::list<KeyValueDifference> differingKeyValues;

std::list<PrimitiveDifference> differingChildren;
};

public:
ComparisonResult(const scene::IMapRootNodePtr& sourceRoot, const scene::IMapRootNodePtr& baseRoot) :
_sourceRoot(sourceRoot),
_baseRoot(baseRoot)
{}

// The collection of entities with the same fingerprint value
std::list<Match> equivalentEntities;

// The collection of differing entities
std::list<EntityDifference> differingEntities;
};

}

}
84 changes: 2 additions & 82 deletions libs/scene/merge/GraphComparer.h
Expand Up @@ -9,94 +9,14 @@
#include "imap.h"
#include "itextstream.h"

#include "ComparisonResult.h"

namespace scene
{

namespace merge
{

class ComparisonResult
{
public:
using Ptr = std::shared_ptr<ComparisonResult>;

private:
// This result instance will hold references to the root nodes of the compared graph
// to ensure the graph stays alive as long as the result
scene::IMapRootNodePtr _sourceRoot;
scene::IMapRootNodePtr _baseRoot;

public:
// Represents a matching node pair
struct Match
{
std::string fingerPrint;
scene::INodePtr sourceNode;
scene::INodePtr baseNode;
};

struct KeyValueDifference
{
std::string key;
std::string value;

enum class Type
{
KeyValueAdded, // key is present on the source entity, but not on the base
KeyValueRemoved, // key is present on the base entity, but not on the source
KeyValueChanged, // key present on both, but value is different
};

Type type;
};

struct PrimitiveDifference
{
std::string fingerprint;
scene::INodePtr node;

enum class Type
{
PrimitiveAdded, // child is present on the source entity, but not on the base
PrimitiveRemoved, // child is present on the base entity, but not on the source
};

Type type;
};

struct EntityDifference
{
std::string fingerprint;
scene::INodePtr node;
std::string entityName;

enum class Type
{
EntityMissingInSource,
EntityMissingInBase,
EntityPresentButDifferent,
};

Type type;

std::list<KeyValueDifference> differingKeyValues;

std::list<PrimitiveDifference> differingChildren;
};

public:
ComparisonResult(const scene::IMapRootNodePtr& sourceRoot, const scene::IMapRootNodePtr& baseRoot) :
_sourceRoot(sourceRoot),
_baseRoot(baseRoot)
{}

// The collection of entities with the same fingerprint value
std::list<Match> equivalentEntities;

// The collection of differing entities
std::list<EntityDifference> differingEntities;
};

class GraphComparer
{
private:
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/map/algorithm/Import.h
Expand Up @@ -3,7 +3,7 @@
#include <istream>
#include <string>
#include <memory>
#include "scene/merge/GraphComparer.h"
#include "scene/merge/ComparisonResult.h"

namespace scene
{
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/scenelib.vcxproj
Expand Up @@ -137,6 +137,7 @@
<ClInclude Include="..\..\libs\scene\InstanceWalkers.h" />
<ClInclude Include="..\..\libs\scene\LayerUsageBreakdown.h" />
<ClInclude Include="..\..\libs\scene\LayerValidityCheckWalker.h" />
<ClInclude Include="..\..\libs\scene\merge\ComparisonResult.h" />
<ClInclude Include="..\..\libs\scene\merge\GraphComparer.h" />
<ClInclude Include="..\..\libs\scene\merge\MergeAction.h" />
<ClInclude Include="..\..\libs\scene\merge\MergeOperation.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/scenelib.vcxproj.filters
Expand Up @@ -112,5 +112,8 @@
<ClInclude Include="..\..\libs\scene\merge\GraphComparer.h">
<Filter>scene\merge</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\scene\merge\ComparisonResult.h">
<Filter>scene\merge</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 9827b56

Please sign in to comment.