using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using XericLibrary.Runtime.Type;
namespace XericLibrary.Runtime.Security
{
///
/// 基本的保全调用方法;
/// 需要手动在委托的前后安置保全标识
///
public class ProgramFlowSecurity : WeaklyObject
{
#region 字段属性
///
/// 外部保护标志位
///
private int conservativeFlag;
///
/// 外部单步标志位
///
private int DoOnceFlag;
#endregion
#region 构造
public ProgramFlowSecurity()
{
conservativeFlag = 0;
DoOnceFlag = 0;
}
#endregion
#region 外部方法
///
/// 标志一段程序的开始
///
///
///
public void Start(T site)
where T : struct, Enum
{
conservativeFlag |= Convert.ToInt32(site);
}
///
/// 标志一段程序的结束
///
///
///
public void Finish(T site)
where T : struct, Enum
{
conservativeFlag &= ~Convert.ToInt32(site);
}
///
/// 尝试开始一段程序
///
///
///
///
public bool TryStart(T site)
where T : struct, Enum
{
if(GetFlag(site))
return false;
Start(site);
return true;
}
///
/// 开始执行一次
///
///
///
///
public bool DoOnceStart(T site)
where T : struct, Enum
{
if(GetFlag(site))
return false;
DoOnceFlag |= Convert.ToInt32(site);
return true;
}
///
/// 复位执行一次的标志
///
///
///
public void ResetDoOnce(T site)
where T : struct, Enum
{
DoOnceFlag &= ~Convert.ToInt32(site);
}
///
/// 获取一段程序的标志位
///
///
///
///
private bool GetFlag(T site)
where T : struct, Enum
{
return (conservativeFlag & Convert.ToInt32(site)) > 0;
}
///
/// 获取一段程序的标志位
///
///
///
///
private bool GetDoOnce(T site)
where T : struct, Enum
{
return (DoOnceFlag & Convert.ToInt32(site)) > 0;
}
#endregion
}
}