Skip to content

Commit

Permalink
Updated ProjectItem + SolutionFolder with implemented native comparis…
Browse files Browse the repository at this point in the history
…on. Issue #8

+RawText

Polynom function extracted as `HashPolynom` + `CalculateHashCode`
  • Loading branch information
3F committed Apr 1, 2019
1 parent 344e823 commit 6902c1e
Show file tree
Hide file tree
Showing 18 changed files with 1,459 additions and 113 deletions.
20 changes: 11 additions & 9 deletions MvsSln/Core/ConfigItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

using System;
using System.Diagnostics;
using net.r_eg.MvsSln.Extensions;

namespace net.r_eg.MvsSln.Core
{
Expand Down Expand Up @@ -85,10 +86,8 @@ public string PlatformByRuleICase

public static bool operator ==(ConfigItem a, ConfigItem b)
{
if(Object.ReferenceEquals(a, null)) {
return Object.ReferenceEquals(b, null);
}
return a.Equals(b);
return Object.ReferenceEquals(a, null) ?
Object.ReferenceEquals(b, null) : a.Equals(b);
}

public static bool operator !=(ConfigItem a, ConfigItem b)
Expand All @@ -103,15 +102,18 @@ public override bool Equals(object obj)
}

var b = (ConfigItem)obj;
return (ConfigurationByRuleICase == b.ConfigurationByRuleICase)
&& (PlatformByRuleICase == b.PlatformByRuleICase);

return ConfigurationByRuleICase == b.ConfigurationByRuleICase
&& PlatformByRuleICase == b.PlatformByRuleICase;
}

public override int GetHashCode()
{
unchecked {
return (Configuration.GetHashCode() << 5) + Configuration.GetHashCode() ^ Platform.GetHashCode();
}
return 0.CalculateHashCode
(
Configuration.GetHashCode(),
Platform.GetHashCode()
);
}

public override string ToString()
Expand Down
3 changes: 2 additions & 1 deletion MvsSln/Core/Guids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
* THE SOFTWARE.
*/

using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;

namespace net.r_eg.MvsSln.Core
{
Expand Down
26 changes: 9 additions & 17 deletions MvsSln/Core/ObjHandlers/HandlerValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

using System;
using net.r_eg.MvsSln.Extensions;

namespace net.r_eg.MvsSln.Core.ObjHandlers
{
Expand All @@ -39,10 +40,8 @@ public struct HandlerValue

public static bool operator ==(HandlerValue a, HandlerValue b)
{
if(Object.ReferenceEquals(a, null)) {
return Object.ReferenceEquals(b, null);
}
return a.Equals(b);
return Object.ReferenceEquals(a, null) ?
Object.ReferenceEquals(b, null) : a.Equals(b);
}

public static bool operator !=(HandlerValue a, HandlerValue b)
Expand All @@ -65,19 +64,12 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
int polynom(int r, int x)
{
unchecked {
return (r << 5) + r ^ x;
}
};

int h = 0;
h = polynom(h, handler.GetHashCode());
h = polynom(h, value.GetHashCode());
h = polynom(h, id.GetHashCode());

return h;
return 0.CalculateHashCode
(
handler.GetHashCode(),
value.GetHashCode(),
id.GetHashCode()
);
}

public HandlerValue(IObjHandler handler)
Expand Down
130 changes: 102 additions & 28 deletions MvsSln/Core/ProjectItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using net.r_eg.MvsSln.Extensions;
using net.r_eg.MvsSln.Log;

namespace net.r_eg.MvsSln.Core
Expand All @@ -37,27 +38,27 @@ namespace net.r_eg.MvsSln.Core
public struct ProjectItem
{
/// <summary>
/// Project GUID
/// Project GUID.
/// </summary>
public string pGuid;

/// <summary>
/// Project type GUID
/// Project type GUID.
/// </summary>
public string pType;

/// <summary>
/// Project name
/// Project name.
/// </summary>
public string name;

/// <summary>
/// Relative path to project
/// Relative path to project.
/// </summary>
public string path;

/// <summary>
/// Full path to project
/// Evaluated full path to project.
/// </summary>
public string fullPath;

Expand All @@ -72,48 +73,125 @@ public struct ProjectItem
public ProjectType EpType;

/// <summary>
/// Evaluate project type via Guid.
/// Evaluate project type via GUID.
/// </summary>
/// <param name="guid">Project type Guid.</param>
/// <param name="guid">Project type GUID.</param>
/// <returns></returns>
[Obsolete("Use `Guids.ProjectTypeBy(string guid)` instead.", false)]
public static ProjectType ProjectTypeBy(string guid)
{
return Guids.ProjectTypeBy(guid);
}

public ProjectItem(string name, ProjectType pType)
: this(name, name, pType)
public static bool operator ==(ProjectItem a, ProjectItem b)
{
return Object.ReferenceEquals(a, null) ?
Object.ReferenceEquals(b, null) : a.Equals(b);
}

public static bool operator !=(ProjectItem a, ProjectItem b)
{
return !(a == b);
}

public override bool Equals(object obj)
{
if(Object.ReferenceEquals(obj, null) || !(obj is ProjectItem)) {
return false;
}

var b = (ProjectItem)obj;

return pGuid == b.pGuid
&& pType == b.pType
&& name == b.name
&& path == b.path
&& fullPath == b.fullPath
&& EpType == b.EpType
&& parent == b.parent;
}

public override int GetHashCode()
{
return 0.CalculateHashCode
(
pGuid.GetHashCode(),
pType.GetHashCode(),
name.GetHashCode(),
path.GetHashCode(),
fullPath.GetHashCode(),
EpType.GetHashCode(),
parent.GetHashCode()
);
}

/// <param name="name">Project name.</param>
/// <param name="pType">Project type GUID.</param>
/// <param name="parent">Parent folder.</param>
public ProjectItem(string name, ProjectType pType, SolutionFolder? parent = null)
: this(name, pType, name, parent)
{

}

public ProjectItem(string pGuid, string name, ProjectType pType)
: this(pGuid, name, name, pType)
/// <param name="name">Project name.</param>
/// <param name="pType">Project type GUID.</param>
/// <param name="path"></param>
/// <param name="parent">Parent folder.</param>
/// <param name="slnDir">To evaluate `fullPath` define path to solution directory.</param>
public ProjectItem(string name, ProjectType pType, string path, SolutionFolder? parent = null, string slnDir = null)
: this(Guid.NewGuid().SlnFormat(), name, pType, path, parent, slnDir)
{

}

public ProjectItem(string name, string path, ProjectType pType, string slnDir = null)
: this(Guid.NewGuid().ToString(), name, path, pType, slnDir)
/// <param name="pGuid">Project GUID.</param>
/// <param name="name">Project name.</param>
/// <param name="pType">Project type GUID.</param>
/// <param name="parent">Parent folder.</param>
public ProjectItem(string pGuid, string name, ProjectType pType, SolutionFolder? parent = null)
: this(pGuid, name, pType, name, parent)
{

}

public ProjectItem(string pGuid, string name, string path, ProjectType pType, string slnDir = null)
/// <param name="pGuid">Project GUID.</param>
/// <param name="name">Project name.</param>
/// <param name="pType">Project type GUID.</param>
/// <param name="path">Relative path to project.</param>
/// <param name="parent">Parent folder.</param>
/// <param name="slnDir">To evaluate `fullPath` define path to solution directory.</param>
public ProjectItem(string pGuid, string name, ProjectType pType, string path, SolutionFolder? parent = null, string slnDir = null)
: this()
{
Init(pGuid, name, path, pType, slnDir);
Init(pGuid, name, path, pType, parent, slnDir);
}

/// <param name="pGuid">Project GUID.</param>
/// <param name="name">Project name.</param>
/// <param name="path">Relative path to project.</param>
/// <param name="pType">Project type GUID.</param>
/// <param name="slnDir">To evaluate `fullPath` define path to solution directory.</param>
public ProjectItem(string pGuid, string name, string path, string pType, string slnDir = null)
: this()
{
Init(pGuid, name, path, pType, slnDir);
}

/// <param name="prj">Initialize data from other project.</param>
public ProjectItem(ProjectItem prj)
{
pGuid = prj.pGuid.ReformatSlnGuid();
pType = prj.pType.ReformatSlnGuid();
name = prj.name;
path = prj.path;
fullPath = prj.fullPath;
EpType = prj.EpType;
parent = prj.parent;
}

/// <param name="raw">Initialize data from raw line.</param>
/// <param name="solutionDir">Path to solution directory.</param>
/// <param name="solutionDir">To evaluate `fullPath` define path to solution directory.</param>
public ProjectItem(string raw, string solutionDir)
: this()
{
Expand All @@ -133,28 +211,28 @@ public ProjectItem(string raw, string solutionDir)
);
}

private void Init(string pGuid, string name, string path, ProjectType pType, string slnDir)
private void Init(string pGuid, string name, string path, ProjectType pType, SolutionFolder? parent, string slnDir)
{
SetProjectType(pType);
Init(pGuid, name, path, slnDir);
SetFields(pGuid, name, path, slnDir, parent);
}

private void Init(string pGuid, string name, string path, string pType, string slnDir)
{
SetProjectType(pType);
Init(pGuid, name, path, slnDir);
SetFields(pGuid, name, path, slnDir);
}

private void Init(string pGuid, string name, string path, string slnDir)
private void SetFields(string pGuid, string name, string path, string slnDir, SolutionFolder? parent = null)
{
this.name = name.Trim();
this.path = path.Trim();
this.pGuid = pGuid.Trim();
this.pGuid = pGuid.ReformatSlnGuid();

SetFullPath(slnDir);

LSender.Send(this, $"ProjectItem ->['{pGuid}'; '{name}'; '{path}'; '{fullPath}'; '{pType}' ]", Message.Level.Trace);
parent = new RefType<SolutionFolder?>();

this.parent = new RefType<SolutionFolder?>(parent);
}

private void SetProjectType(ProjectType pType)
Expand All @@ -169,16 +247,12 @@ private void SetProjectType(ProjectType pType)
/// <param name="pType"></param>
private void SetProjectType(string pType)
{
this.pType = pType;
this.pType = pType.ReformatSlnGuid();
EpType = Guids.ProjectTypeBy(pType);
}

private void SetFullPath(string slnDir)
{
if(slnDir == null) {
return;
}

if(Path.IsPathRooted(path)) {
fullPath = path;
}
Expand Down
36 changes: 36 additions & 0 deletions MvsSln/Core/RawText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
* THE SOFTWARE.
*/

using System;
using System.Diagnostics;
using System.Text;
using net.r_eg.MvsSln.Extensions;

namespace net.r_eg.MvsSln.Core
{
Expand All @@ -49,6 +51,40 @@ public static implicit operator RawText(string str)
return new RawText(str);
}

public static bool operator ==(RawText a, RawText b)
{
return Object.ReferenceEquals(a, null) ?
Object.ReferenceEquals(b, null) : a.Equals(b);
}

public static bool operator !=(RawText a, RawText b)
{
return !(a == b);
}

public override bool Equals(object obj)
{
if(Object.ReferenceEquals(obj, null) || !(obj is RawText)) {
return false;
}

var b = (RawText)obj;

return data == b.data
&& trimmed == b.trimmed
&& encoding == b.encoding;
}

public override int GetHashCode()
{
return 0.CalculateHashCode
(
data.GetHashCode(),
trimmed.GetHashCode(),
encoding.GetHashCode()
);
}

public override string ToString()
{
return data;
Expand Down
Loading

0 comments on commit 6902c1e

Please sign in to comment.