10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Add enumUtils to handle enum getFlags(value) and All corectly

This commit is contained in:
Mickaël Véril 2020-01-28 17:25:49 +01:00
parent ed403e92f9
commit 69c4afa43c

View File

@ -9,20 +9,25 @@ class excitationTypes {
static get Triplet() { return new excitationType(1 << 8, "3") } static get Triplet() { return new excitationType(1 << 8, "3") }
// Max bit shifts is 31 because int are int32 So 1 << 31 are -2147483648 // Max bit shifts is 31 because int are int32 So 1 << 31 are -2147483648
static get Others() { return new excitationType(1 << 31, String.raw`\mathrm{Others}`) } static get Others() { return new excitationType(1 << 31, String.raw`\mathrm{Others}`) }
static get All() { static get All() { return EnumUltils.getAll(this,excitationType)}
static GetFlags(value){return EnumUltils.GetFlags(value,this,excitationType)}
}
class EnumUltils{
static getAll(enumClass,valueType) {
var lst = [] var lst = []
for (const prop of Object.getOwnPropertyNames(excitationTypes)) { for (const prop of Object.getOwnPropertyNames(enumClass)) {
if (prop != "All") { if (prop != "All") {
const value = excitationTypes[prop] const value = enumClass[prop]
if (trueTypeOf(value) == excitationType.name) { if (trueTypeOf(value) == valueType.name) {
lst.push([prop, value]) lst.push([prop, value])
} }
} }
} }
return lst return lst
} }
static GetFlags(value) { static GetFlags(value,enumClass,valueType) {
return this.All().filter((x) => { value & x[1] }) return this.getAll(enumClass,valueType).filter((x) => { value & x[1] })
} }
} }
@ -321,6 +326,8 @@ class dataFileBase {
class VertExcitationKinds{ class VertExcitationKinds{
static get Absorbtion() {return new VertExcitationKind(1, String.raw`\mathrm{A}`)} static get Absorbtion() {return new VertExcitationKind(1, String.raw`\mathrm{A}`)}
static get Fluorescence() {return new VertExcitationKind(1<<1, String.raw`\mathrm{F}`)} static get Fluorescence() {return new VertExcitationKind(1<<1, String.raw`\mathrm{F}`)}
static get All() { return EnumUltils.getAll(this,VertExcitationKind)}
static GetFlags(value){return EnumUltils.GetFlags(value,this,VertExcitationKind)}
} }
class VertDataFile extends dataFileBase { class VertDataFile extends dataFileBase {
constructor(VertExcitationKind) { constructor(VertExcitationKind) {