/[RomCheater]/trunk/RomCheater.Logging/logger.cs
ViewVC logotype

Diff of /trunk/RomCheater.Logging/logger.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Logging/logger.cs	2012/05/10 15:30:14	115
+++ trunk/RomCheater.Logging/logger.cs	2012/05/10 15:30:37	116
@@ -14,28 +14,28 @@
     }
 
 
-    #region MesageLogger
-    //[Flags]
-    public class loggerflags
+    #region loggerflags
+    public class loggerflagsbase<TValue> 
+        where TValue : IConvertible
     {
-        static loggerflags()
+         static loggerflagsbase()
         {
-            value_pairs = new Dictionary<ushort, EnumNameValuePair<string, ushort>>();
-            name_pairs = new Dictionary<string, EnumNameValuePair<string, ushort>>();
+            value_pairs = new Dictionary<TValue, EnumNameValuePair<TValue>>();
+            name_pairs = new Dictionary<string, EnumNameValuePair<TValue>>();
             
             init_dicts();
         }
-        protected loggerflags() 
+        protected loggerflagsbase() 
         {
             CurrentValue = NONE;
         }
-        //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair<string, ushort>("", t); }
-        protected loggerflags(EnumNameValuePair<string, ushort> t) { CurrentValue = t; }
-        protected loggerflags(loggerflags t) { this.CurrentValue = t.CurrentValue; }
+        //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair< ushort>("", t); }
+        protected loggerflagsbase(EnumNameValuePair< TValue> t) { CurrentValue = t; }
+        protected loggerflagsbase(loggerflagsbase<TValue> t) { this.CurrentValue = t.CurrentValue; }
         private static void init_dicts()
         {
-            value_pairs = new Dictionary<ushort, EnumNameValuePair<string, ushort>>();
-            name_pairs = new Dictionary<string, EnumNameValuePair<string, ushort>>();
+            value_pairs = new Dictionary<TValue, EnumNameValuePair< TValue>>();
+            name_pairs = new Dictionary<string, EnumNameValuePair< TValue>>();
             add_dict_entry(NONE);
             add_dict_entry(INFO);
             add_dict_entry(DEBUG);
@@ -46,7 +46,7 @@
             add_dict_entry(ALL);
         }
 
-        private static void add_dict_entry( EnumNameValuePair<string, ushort> value)
+        private static void add_dict_entry(EnumNameValuePair<TValue> value)
         {
             try
             {
@@ -57,19 +57,19 @@
         }
 
         #region implicit operators
-        public static implicit operator loggerflags(EnumNameValuePair<string, ushort> t) { return new loggerflags(t); }
-        public static implicit operator EnumNameValuePair<string, ushort>(loggerflags t) { return new loggerflags(t); }
-        public static implicit operator loggerflags(ushort t) 
+        public static implicit operator loggerflagsbase<TValue>(EnumNameValuePair<TValue> t) { return new loggerflagsbase<TValue>(t); }
+        public static implicit operator EnumNameValuePair<TValue>(loggerflagsbase<TValue> t) { return new loggerflagsbase<TValue>(t); }
+        public static implicit operator loggerflagsbase<TValue>(TValue t) 
         {
-            foreach (KeyValuePair<ushort, EnumNameValuePair<string, ushort>> pair in value_pairs) { EnumNameValuePair<string, ushort> l = pair.Value; if (l.Value == t) { return new loggerflags(l); } }
-            return loggerflags.NONE;
+            foreach (KeyValuePair<TValue, EnumNameValuePair<TValue>> pair in value_pairs) { EnumNameValuePair<TValue> l = pair.Value; if (l.Value.Equals(t)) { return new loggerflagsbase<TValue>(l); } }
+            return loggerflagsbase<TValue>.NONE;
         }
-        public static implicit operator ushort(loggerflags t) { return t.CurrentValue.Value; }
-        public static implicit operator string(loggerflags t) { return t.CurrentValue.Name; }
+        public static implicit operator TValue(loggerflagsbase<TValue> t) { return t.CurrentValue.Value; }
+        public static implicit operator string(loggerflagsbase<TValue> t) { return t.CurrentValue.Name; }
 
         #region operator overloads
-        public static bool operator ==(loggerflags x, loggerflags y) { return x.CurrentValue == y.CurrentValue; }
-        public static bool operator !=(loggerflags x, loggerflags y) { return x.CurrentValue != y.CurrentValue; }
+        public static bool operator ==(loggerflagsbase<TValue> x, loggerflagsbase<TValue> y) { return x.CurrentValue == y.CurrentValue; }
+        public static bool operator !=(loggerflagsbase<TValue> x, loggerflagsbase<TValue> y) { return x.CurrentValue != y.CurrentValue; }
         public override bool Equals(object obj)
         {
             loggerflags t = (obj as loggerflags);
@@ -82,41 +82,58 @@
         }
         public override string ToString()
         {
+            
             return CurrentValue.ToString();
         }
         #endregion
         #endregion
         #region binary bit flags
-        public static EnumNameValuePair<string, ushort> NONE = new EnumNameValuePair<string, ushort>("NONE", Binary<ushort>.ToValue("00000"));
-        public static EnumNameValuePair<string, ushort> INFO = new EnumNameValuePair<string, ushort>("INFO", Binary<ushort>.ToValue("00001"));
-        public static EnumNameValuePair<string, ushort> DEBUG = new EnumNameValuePair<string, ushort>("DEBUG", Binary<ushort>.ToValue("00010"));
-        public static EnumNameValuePair<string, ushort> ERROR = new EnumNameValuePair<string, ushort>("ERROR", Binary<ushort>.ToValue("00100"));
-        public static EnumNameValuePair<string, ushort> VERBOSE_DEBUG = new EnumNameValuePair<string, ushort>("VERBOSE_DEBUG", Binary<ushort>.ToValue("01000"));
-        public static EnumNameValuePair<string, ushort> VERBOSE_ERROR = new EnumNameValuePair<string, ushort>("VERBOSE_ERROR", Binary<ushort>.ToValue("10000"));
-        public static EnumNameValuePair<string, ushort> DEFAULT = new EnumNameValuePair<string, ushort>("DEFAULT", (ushort)(INFO | DEBUG | ERROR));
-        public static EnumNameValuePair<string, ushort> ALL = new EnumNameValuePair<string, ushort>("ALL", (ushort)(DEFAULT | VERBOSE_DEBUG | VERBOSE_ERROR));
+        public static EnumNameValuePair<TValue> NONE = new EnumNameValuePair<TValue>("NONE", Binary<TValue>.ToValue("00000"));
+        public static EnumNameValuePair<TValue> INFO = new EnumNameValuePair<TValue>("INFO", Binary<TValue>.ToValue("00001"));
+        public static EnumNameValuePair<TValue> DEBUG = new EnumNameValuePair<TValue>("DEBUG", Binary<TValue>.ToValue("00010"));
+        public static EnumNameValuePair<TValue> ERROR = new EnumNameValuePair<TValue>("ERROR", Binary<TValue>.ToValue("00100"));
+        public static EnumNameValuePair<TValue> VERBOSE_DEBUG = new EnumNameValuePair<TValue>("VERBOSE_DEBUG", Binary<TValue>.ToValue("01000"));
+        public static EnumNameValuePair<TValue> VERBOSE_ERROR = new EnumNameValuePair<TValue>("VERBOSE_ERROR", Binary<TValue>.ToValue("10000"));
+        public static EnumNameValuePair<TValue> DEFAULT = new EnumNameValuePair<TValue>("DEFAULT", EnumNameValuePair<TValue>.bitwise_or(INFO,DEBUG,ERROR));
+        public static EnumNameValuePair<TValue> ALL = new EnumNameValuePair<TValue>("ALL", EnumNameValuePair<TValue>.bitwise_or(DEFAULT, VERBOSE_DEBUG, VERBOSE_ERROR));
         #endregion
 
-        protected static Dictionary<ushort, EnumNameValuePair<string, ushort>> value_pairs;
-        protected static Dictionary<string, EnumNameValuePair<string, ushort>> name_pairs;
-        private EnumNameValuePair<string, ushort> CurrentValue { get; set; }
+        protected static Dictionary<TValue, EnumNameValuePair<TValue>> value_pairs;
+        protected static Dictionary<string, EnumNameValuePair<TValue>> name_pairs;
+        private EnumNameValuePair<TValue> CurrentValue { get; set; }
 
-        public bool HasFlag(ushort flag)
+        public bool HasFlag(TValue flag)
         {
             bool hasflag = false;
-            ushort value = this.CurrentValue;
-            if ((flag & value) != 0)
+            TValue value = this.CurrentValue;
+            if (!(EnumNameValuePair<TValue>.bitwise_and(flag, value)).Equals(0))
                 hasflag = true;
             return hasflag;
         }
 
-        public static List<ushort> GetValues() { return value_pairs.Keys.ToList(); }
+        public static List<TValue> GetValues() { return value_pairs.Keys.ToList(); }
         public static List<string> GetNames() { return name_pairs.Keys.ToList(); }
 
         public string Name { get { return CurrentValue.Name; } }
-        public ushort Value { get { return CurrentValue.Value; } }
+        public TValue Value { get { return CurrentValue.Value; } }
+    }
+    //[Flags]
+    public class loggerflags : loggerflagsbase<ushort>
+    {
+          protected loggerflags() :base()        {        }
+        //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair< ushort>("", t); }
+          protected loggerflags(EnumNameValuePair<ushort> t) : base(t) { }
+          protected loggerflags(loggerflagsbase<ushort> t) : base(t) { }
+        #region implicit operators
+          public static implicit operator loggerflags(EnumNameValuePair<ushort> t) { return new loggerflags(t); }
+          public static implicit operator EnumNameValuePair<ushort>(loggerflags t) { return new loggerflags(t.Value); }
+          public static implicit operator ushort(loggerflags t) { return t.Value; }
+          public static implicit operator loggerflags(ushort t) { return new loggerflags(t); }
+          public static implicit operator string(loggerflags t) { return t.Name; }
+        #endregion
 
     }
+    
     public static class logger
     {
         private static loggerflags logging_flags;

 

  ViewVC Help
Powered by ViewVC 1.1.22