purview.cs

来自「报刊广告管理系统。CSharp编写」· CS 代码 · 共 145 行

CS
145
字号
using System;

namespace WWAM
{
	public class Purview
	{
		int pValue = 0;
		public Purview()
		{

		}
		public Purview(int val)
		{
			pValue = val;
		}
		public Purview(bool[] vals)
		{
			pValue = GetInt(vals);
		}
		public int PurviewValue
		{
			get
			{
				return pValue;
			}
			set
			{
				pValue = value;
			}
		}
		public bool this[int index]
		{
			get
			{
				return GetValue(pValue,index);
			}
			set
			{
				pValue = SetValue(pValue,index,value);
			}

		}
		public bool[] ItemsValue
		{
			get
			{
				bool[] bools = new bool[31];
				GetArray(bools,pValue);
				return bools;
			}
		}
		#region Static Method
		public static bool GetValue(int Purview, int digit)
		{
			if(digit<0 || digit>30)
			{
				return false;
			}
			else
			{
				return (Purview & (1<<digit))!=0;
			}
		}

		public static int SetValue(int Purview, int digit, bool val)
		{
			if(digit<0 || digit>30)
			{
				return Purview;
			}
			else
			{
				if(val)
				{
					return (Purview | (1 << digit));
				}
				else
				{
					return (Purview & (~(1 << digit)));
				}
			}
		}

		public static int AllClear()
		{
			return 0;
		}

		public static int AllSet()
		{
			return 0x7FFFFFFF;
		}

		public static void GetArray(bool[] bools , int Purview)
		{
			if(bools.Length!=31)
			{
				bools = new bool[31];
			}
			for(int i=0;i<31;i++)
			{
				bools[i] = (Purview % 2 ==1);
				Purview >>=1;
			}			
		}

		public static int GetInt(bool[] bools)
		{
			int k=0;
			for(int i = Math.Min(bools.Length,30);i>=0;i--)
			{
				k<<=1;
				k += bools[i]?1:0;
			}
			return k;
		}
		public static int GetValue(int PurView, int pos , int digits)
		{
			if(pos<0 || pos+digits>30)
			{
				return 0;
			}
			else
			{
				int filter = (1<<digits)-1;
				return (PurView>>pos)&filter;
			}
		}
		public static int SetValue(int PurView, int pos , int digits , int val)
		{
			if(pos<0 || pos+digits>30)
			{
				return 0;
			}
			else
			{
				int filter = ~(((1<<digits)-1)<<pos);
				val = val<<pos;
				return (PurView&filter)|val;
			}
		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?