초기커밋
This commit is contained in:
75
ServerCore/Pattern/Flags.cs
Normal file
75
ServerCore/Pattern/Flags.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Axion.Collections.Concurrent;
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
//=============================================================================================
|
||||
// 각종 시스템에 사용할 플래그 설정을 타입화 하여 관리할 수 있는 제네릭 클래스 이다.
|
||||
//
|
||||
// author : kangms
|
||||
//
|
||||
//=============================================================================================
|
||||
|
||||
public class Flags<T>
|
||||
{
|
||||
private readonly ConcurrentHashSet<T> m_switchs = new();
|
||||
|
||||
public bool hasFlag(T flag)
|
||||
{
|
||||
return m_switchs.Contains(flag);
|
||||
}
|
||||
|
||||
public void setFlag(T flag, bool isEnable)
|
||||
{
|
||||
if (isEnable)
|
||||
{
|
||||
m_switchs.AddOrUpdate(flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_switchs.Remove(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public bool isEmptyFlags()
|
||||
{
|
||||
return m_switchs.IsEmpty;
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
m_switchs.Clear();
|
||||
}
|
||||
|
||||
public virtual Flags<T> clone()
|
||||
{
|
||||
var cloned = new Flags<T>();
|
||||
|
||||
foreach(var value in m_switchs)
|
||||
{
|
||||
cloned.getData().AddOrUpdate(value);
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public virtual void deepCopy(Flags<T> other)
|
||||
{
|
||||
reset();
|
||||
|
||||
foreach (var value in other.getData())
|
||||
{
|
||||
m_switchs.AddOrUpdate(value);
|
||||
}
|
||||
}
|
||||
|
||||
public ConcurrentHashSet<T> getData() => m_switchs;
|
||||
}
|
||||
Reference in New Issue
Block a user