You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.2 KiB

// ------------------------------------------------------------------------
// 🚀 Project Active8
// 🔗 Active Thing (activething.com) git.activething.com/go
//
// File name actor_state_flags.go
// ✍️ Created by DEV
// 📅 Modified 07/12/2024
//
// 🔒 Copyright 2024 activething.com
//
// 📜 LICENSE --------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package brbac
import "math/bits"
const (
ActorFlagVerified ActorFlags = 0b00000001
ActorFlagRequired ActorFlags = 0b00000010
ActorFlagRestricted ActorFlags = 0b00000011
ActorFlagLimited ActorFlags = 0b00000100
ActorFlagUnique ActorFlags = 0b00000101 // Solo puede existir un actor simultaneamente
)
type (
ActorFlags uint8
)
func (a ActorFlags) Has(flag ActorFlags) bool {
return a&flag != 0
}
func (a ActorFlags) HasVerified() bool {
return a&ActorFlagVerified != 0
}
func (a ActorFlags) HasRequired() bool {
return a&ActorFlagRequired != 0
}
func (a ActorFlags) HasRestricted() bool {
return a&ActorFlagRestricted != 0
}
func (a ActorFlags) HasLimited() bool {
return a&ActorFlagLimited != 0
}
func (a ActorFlags) HasUnique () bool {
return a&ActorFlagUnique != 0
}
func (a ActorFlags) Count() int {
if a == 0 {
return 0
}
return bits.OnesCount8(uint8(a))
}
func (a ActorFlags) Actives() []ActorFlags {
var l []ActorFlags
if a > 0 {
for _, f := range g.actorFlags {
if a&f != 0 {
l = append(l, f)
}
}
}
return l
}
func (a ActorFlags) Set(flag ActorFlags) ActorFlags {
return a | flag
}
func (a ActorFlags) Del(flag ActorFlags) ActorFlags {
return a &^ flag
}
func (a ActorFlags) Clear() ActorFlags {
return 0
}

Powered by TurnKey Linux.