// Mono.Util.CorCompare.CompletionInfo
//
// Author(s):
// Piers Haken (piersh@friskit.com)
//
// (C) 2001-2002 Piers Haken
using System;
using System.Reflection;
using System.Xml;
namespace Mono.Util.CorCompare {
///
/// Represents the 3 different stages of completion that an element can be in.
///
public enum CompletionTypes
{
Complete,
Todo,
Missing
}
///
/// Represents the amount of work done on a node
///
///
/// created by - Piersh
/// created on - 3/2/2002 1:12:00 AM
///
public struct CompletionInfo
{
public int cComplete;
public int cTodo;
public int cMissing;
///
/// converts a CompletionTypes into a CompletionInfo
/// sets the corresponding field to '1'
///
/// the CompletionTypes to convert
public CompletionInfo (CompletionTypes ct)
{
cComplete = cTodo = cMissing = 0;
switch (ct)
{
case CompletionTypes.Complete:
cComplete = 1;
break;
case CompletionTypes.Todo:
cTodo = 1;
break;
case CompletionTypes.Missing:
cMissing = 1;
break;
default:
throw new Exception ("Invalid CompletionType: "+ct.ToString ());
}
}
///
/// counts the total number of elements represented by this info
///
public int cTotal
{
get
{
return cComplete + cTodo + cMissing;
}
}
///
/// adds two CompletionInfos together
///
///
public void Add (CompletionInfo ci)
{
cComplete += ci.cComplete;
cTodo += ci.cTodo;
cMissing += ci.cMissing;
}
///
/// increments the corresponding field
///
///
public void Add (CompletionTypes ct)
{
switch (ct)
{
case CompletionTypes.Complete:
cComplete ++;
break;
case CompletionTypes.Todo:
cTodo ++;
break;
case CompletionTypes.Missing:
cMissing ++;
break;
default:
throw new Exception ("Invalid CompletionType: "+ct.ToString ());
}
}
///
/// decrements the corresponding field
///
///
public void Sub (CompletionTypes ct)
{
switch (ct)
{
case CompletionTypes.Complete:
cComplete --;
break;
case CompletionTypes.Todo:
cTodo --;
break;
case CompletionTypes.Missing:
cMissing --;
break;
default:
throw new Exception ("Invalid CompletionType: "+ct.ToString ());
}
if (cComplete < 0 || cTodo < 0 || cMissing < 0)
throw new Exception ("Completion underflow on subtract");
}
///
/// adds appropriate 'missing', 'todo' & 'complete' attributes to an XmlElement
///
///
public void SetAttributes (XmlElement elt)
{
elt.SetAttribute ("missing", cMissing.ToString ());
elt.SetAttribute ("todo", cTodo.ToString ());
int percentComplete = (cTotal == 0) ? 100 : (100 - 100 * (cMissing + cTodo) / cTotal);
elt.SetAttribute ("complete", percentComplete.ToString ());
}
}
}