/[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/09 23:23:38	99
+++ trunk/RomCheater.Logging/logger.cs	2012/05/10 13:55:44	111
@@ -15,24 +15,110 @@
 
 
     #region MesageLogger
-    [Flags]
-    public enum loggerflags :ushort
+    //[Flags]
+    public class loggerflags
     {
-        NONE = 0x0000,              // 00000
-        INFO = 0x0001,              // 00001
-        DEBUG = 0x0002,             // 00010
-        ERROR= 0x0004,              // 00100
-        VERBOSE_DEBUG = 0x0008,             // 01000
-        VERBOSE_ERROR = 0x0010,             // 10000
-        DEFAULT = INFO | ERROR | DEBUG,
-        ALL = DEFAULT | VERBOSE_DEBUG | VERBOSE_ERROR
+        static loggerflags()
+        {
+            value_pairs = new Dictionary<ushort, EnumNameValuePair<string, ushort>>();
+            name_pairs = new Dictionary<string, EnumNameValuePair<string, ushort>>();
+            
+            init_dicts();
+        }
+        protected loggerflags() 
+        {
+            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; }
+        private static void init_dicts()
+        {
+            value_pairs = new Dictionary<ushort, EnumNameValuePair<string, ushort>>();
+            name_pairs = new Dictionary<string, EnumNameValuePair<string, ushort>>();
+            add_dict_entry(NONE);
+            add_dict_entry(INFO);
+            add_dict_entry(DEBUG);
+            add_dict_entry(ERROR);
+            add_dict_entry(VERBOSE_DEBUG);
+            add_dict_entry(VERBOSE_ERROR);
+            add_dict_entry(DEFAULT);
+            add_dict_entry(ALL);
+        }
+
+        private static void add_dict_entry( EnumNameValuePair<string, ushort> value)
+        {
+            try
+            {
+                value_pairs.Add(value, value);
+                name_pairs.Add(value, value);
+            }
+            catch { }
+        }
+
+        #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) 
+        {
+            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;
+        }
+        public static implicit operator ushort(loggerflags t) { return t.CurrentValue.Value; }
+        public static implicit operator string(loggerflags 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 override bool Equals(object obj)
+        {
+            loggerflags t = (obj as loggerflags);
+            if (t == null) return false;
+            return this.CurrentValue.Equals(t);
+        }
+        public override int GetHashCode()
+        {
+            return CurrentValue.GetHashCode();
+        }
+        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));
+        #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; }
+
+        public bool HasFlag(ushort flag)
+        {
+            bool hasflag = false;
+            ushort value = this.CurrentValue;
+            if ((flag & value) != 0)
+                hasflag = true;
+            return hasflag;
+        }
+
+        public static List<ushort> GetValues() { return value_pairs.Keys.ToList(); }
+        public static List<string> GetNames() { return name_pairs.Keys.ToList(); }
     }
     public static class logger
     {
         private static loggerflags logging_flags;
         static logger() { SetLoggingFlags(loggerflags.DEFAULT); }
         public static void SetLoggingFlags(loggerflags flags) { logging_flags = flags; }
-        public static loggerflags GetLoggingFlags() { return logging_flags; }
+        public static ushort GetLoggingFlags() { return logging_flags; }
         #region sub-classes
         private static string CreateTimeStamp()
         {

 

  ViewVC Help
Powered by ViewVC 1.1.22