ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.Logging/logger.cs
(Generate patch)

Comparing trunk/RomCheater.Logging/logger.cs (file contents):
Revision 115 by william, Thu May 10 14:01:31 2012 UTC vs.
Revision 116 by william, Thu May 10 15:30:37 2012 UTC

# Line 14 | Line 14 | namespace RomCheater.Logging
14      }
15  
16  
17 <    #region MesageLogger
18 <    //[Flags]
19 <    public class loggerflags
17 >    #region loggerflags
18 >    public class loggerflagsbase<TValue>
19 >        where TValue : IConvertible
20      {
21 <        static loggerflags()
21 >         static loggerflagsbase()
22          {
23 <            value_pairs = new Dictionary<ushort, EnumNameValuePair<string, ushort>>();
24 <            name_pairs = new Dictionary<string, EnumNameValuePair<string, ushort>>();
23 >            value_pairs = new Dictionary<TValue, EnumNameValuePair<TValue>>();
24 >            name_pairs = new Dictionary<string, EnumNameValuePair<TValue>>();
25              
26              init_dicts();
27          }
28 <        protected loggerflags()
28 >        protected loggerflagsbase()
29          {
30              CurrentValue = NONE;
31          }
32 <        //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair<string, ushort>("", t); }
33 <        protected loggerflags(EnumNameValuePair<string, ushort> t) { CurrentValue = t; }
34 <        protected loggerflags(loggerflags t) { this.CurrentValue = t.CurrentValue; }
32 >        //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair< ushort>("", t); }
33 >        protected loggerflagsbase(EnumNameValuePair< TValue> t) { CurrentValue = t; }
34 >        protected loggerflagsbase(loggerflagsbase<TValue> t) { this.CurrentValue = t.CurrentValue; }
35          private static void init_dicts()
36          {
37 <            value_pairs = new Dictionary<ushort, EnumNameValuePair<string, ushort>>();
38 <            name_pairs = new Dictionary<string, EnumNameValuePair<string, ushort>>();
37 >            value_pairs = new Dictionary<TValue, EnumNameValuePair< TValue>>();
38 >            name_pairs = new Dictionary<string, EnumNameValuePair< TValue>>();
39              add_dict_entry(NONE);
40              add_dict_entry(INFO);
41              add_dict_entry(DEBUG);
# Line 46 | Line 46 | namespace RomCheater.Logging
46              add_dict_entry(ALL);
47          }
48  
49 <        private static void add_dict_entry( EnumNameValuePair<string, ushort> value)
49 >        private static void add_dict_entry(EnumNameValuePair<TValue> value)
50          {
51              try
52              {
# Line 57 | Line 57 | namespace RomCheater.Logging
57          }
58  
59          #region implicit operators
60 <        public static implicit operator loggerflags(EnumNameValuePair<string, ushort> t) { return new loggerflags(t); }
61 <        public static implicit operator EnumNameValuePair<string, ushort>(loggerflags t) { return new loggerflags(t); }
62 <        public static implicit operator loggerflags(ushort t)
60 >        public static implicit operator loggerflagsbase<TValue>(EnumNameValuePair<TValue> t) { return new loggerflagsbase<TValue>(t); }
61 >        public static implicit operator EnumNameValuePair<TValue>(loggerflagsbase<TValue> t) { return new loggerflagsbase<TValue>(t); }
62 >        public static implicit operator loggerflagsbase<TValue>(TValue t)
63          {
64 <            foreach (KeyValuePair<ushort, EnumNameValuePair<string, ushort>> pair in value_pairs) { EnumNameValuePair<string, ushort> l = pair.Value; if (l.Value == t) { return new loggerflags(l); } }
65 <            return loggerflags.NONE;
64 >            foreach (KeyValuePair<TValue, EnumNameValuePair<TValue>> pair in value_pairs) { EnumNameValuePair<TValue> l = pair.Value; if (l.Value.Equals(t)) { return new loggerflagsbase<TValue>(l); } }
65 >            return loggerflagsbase<TValue>.NONE;
66          }
67 <        public static implicit operator ushort(loggerflags t) { return t.CurrentValue.Value; }
68 <        public static implicit operator string(loggerflags t) { return t.CurrentValue.Name; }
67 >        public static implicit operator TValue(loggerflagsbase<TValue> t) { return t.CurrentValue.Value; }
68 >        public static implicit operator string(loggerflagsbase<TValue> t) { return t.CurrentValue.Name; }
69  
70          #region operator overloads
71 <        public static bool operator ==(loggerflags x, loggerflags y) { return x.CurrentValue == y.CurrentValue; }
72 <        public static bool operator !=(loggerflags x, loggerflags y) { return x.CurrentValue != y.CurrentValue; }
71 >        public static bool operator ==(loggerflagsbase<TValue> x, loggerflagsbase<TValue> y) { return x.CurrentValue == y.CurrentValue; }
72 >        public static bool operator !=(loggerflagsbase<TValue> x, loggerflagsbase<TValue> y) { return x.CurrentValue != y.CurrentValue; }
73          public override bool Equals(object obj)
74          {
75              loggerflags t = (obj as loggerflags);
# Line 82 | Line 82 | namespace RomCheater.Logging
82          }
83          public override string ToString()
84          {
85 +            
86              return CurrentValue.ToString();
87          }
88          #endregion
89          #endregion
90          #region binary bit flags
91 <        public static EnumNameValuePair<string, ushort> NONE = new EnumNameValuePair<string, ushort>("NONE", Binary<ushort>.ToValue("00000"));
92 <        public static EnumNameValuePair<string, ushort> INFO = new EnumNameValuePair<string, ushort>("INFO", Binary<ushort>.ToValue("00001"));
93 <        public static EnumNameValuePair<string, ushort> DEBUG = new EnumNameValuePair<string, ushort>("DEBUG", Binary<ushort>.ToValue("00010"));
94 <        public static EnumNameValuePair<string, ushort> ERROR = new EnumNameValuePair<string, ushort>("ERROR", Binary<ushort>.ToValue("00100"));
95 <        public static EnumNameValuePair<string, ushort> VERBOSE_DEBUG = new EnumNameValuePair<string, ushort>("VERBOSE_DEBUG", Binary<ushort>.ToValue("01000"));
96 <        public static EnumNameValuePair<string, ushort> VERBOSE_ERROR = new EnumNameValuePair<string, ushort>("VERBOSE_ERROR", Binary<ushort>.ToValue("10000"));
97 <        public static EnumNameValuePair<string, ushort> DEFAULT = new EnumNameValuePair<string, ushort>("DEFAULT", (ushort)(INFO | DEBUG | ERROR));
98 <        public static EnumNameValuePair<string, ushort> ALL = new EnumNameValuePair<string, ushort>("ALL", (ushort)(DEFAULT | VERBOSE_DEBUG | VERBOSE_ERROR));
91 >        public static EnumNameValuePair<TValue> NONE = new EnumNameValuePair<TValue>("NONE", Binary<TValue>.ToValue("00000"));
92 >        public static EnumNameValuePair<TValue> INFO = new EnumNameValuePair<TValue>("INFO", Binary<TValue>.ToValue("00001"));
93 >        public static EnumNameValuePair<TValue> DEBUG = new EnumNameValuePair<TValue>("DEBUG", Binary<TValue>.ToValue("00010"));
94 >        public static EnumNameValuePair<TValue> ERROR = new EnumNameValuePair<TValue>("ERROR", Binary<TValue>.ToValue("00100"));
95 >        public static EnumNameValuePair<TValue> VERBOSE_DEBUG = new EnumNameValuePair<TValue>("VERBOSE_DEBUG", Binary<TValue>.ToValue("01000"));
96 >        public static EnumNameValuePair<TValue> VERBOSE_ERROR = new EnumNameValuePair<TValue>("VERBOSE_ERROR", Binary<TValue>.ToValue("10000"));
97 >        public static EnumNameValuePair<TValue> DEFAULT = new EnumNameValuePair<TValue>("DEFAULT", EnumNameValuePair<TValue>.bitwise_or(INFO,DEBUG,ERROR));
98 >        public static EnumNameValuePair<TValue> ALL = new EnumNameValuePair<TValue>("ALL", EnumNameValuePair<TValue>.bitwise_or(DEFAULT, VERBOSE_DEBUG, VERBOSE_ERROR));
99          #endregion
100  
101 <        protected static Dictionary<ushort, EnumNameValuePair<string, ushort>> value_pairs;
102 <        protected static Dictionary<string, EnumNameValuePair<string, ushort>> name_pairs;
103 <        private EnumNameValuePair<string, ushort> CurrentValue { get; set; }
101 >        protected static Dictionary<TValue, EnumNameValuePair<TValue>> value_pairs;
102 >        protected static Dictionary<string, EnumNameValuePair<TValue>> name_pairs;
103 >        private EnumNameValuePair<TValue> CurrentValue { get; set; }
104  
105 <        public bool HasFlag(ushort flag)
105 >        public bool HasFlag(TValue flag)
106          {
107              bool hasflag = false;
108 <            ushort value = this.CurrentValue;
109 <            if ((flag & value) != 0)
108 >            TValue value = this.CurrentValue;
109 >            if (!(EnumNameValuePair<TValue>.bitwise_and(flag, value)).Equals(0))
110                  hasflag = true;
111              return hasflag;
112          }
113  
114 <        public static List<ushort> GetValues() { return value_pairs.Keys.ToList(); }
114 >        public static List<TValue> GetValues() { return value_pairs.Keys.ToList(); }
115          public static List<string> GetNames() { return name_pairs.Keys.ToList(); }
116  
117          public string Name { get { return CurrentValue.Name; } }
118 <        public ushort Value { get { return CurrentValue.Value; } }
118 >        public TValue Value { get { return CurrentValue.Value; } }
119 >    }
120 >    //[Flags]
121 >    public class loggerflags : loggerflagsbase<ushort>
122 >    {
123 >          protected loggerflags() :base()        {        }
124 >        //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair< ushort>("", t); }
125 >          protected loggerflags(EnumNameValuePair<ushort> t) : base(t) { }
126 >          protected loggerflags(loggerflagsbase<ushort> t) : base(t) { }
127 >        #region implicit operators
128 >          public static implicit operator loggerflags(EnumNameValuePair<ushort> t) { return new loggerflags(t); }
129 >          public static implicit operator EnumNameValuePair<ushort>(loggerflags t) { return new loggerflags(t.Value); }
130 >          public static implicit operator ushort(loggerflags t) { return t.Value; }
131 >          public static implicit operator loggerflags(ushort t) { return new loggerflags(t); }
132 >          public static implicit operator string(loggerflags t) { return t.Name; }
133 >        #endregion
134  
135      }
136 +    
137      public static class logger
138      {
139          private static loggerflags logging_flags;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines