enumeration

How to add a method to a Scala Enumeration object?

混江龙づ霸主 提交于 2019-12-10 18:27:09
问题 I'm using Scala 2.8 and defining an Enumeration like this: object Stooges extends Enumeration { type Stooge = Value val Larry, Curly, Moe = Value } And I want to add a method to this Enumeration that cycles to the "next" stooge. I can define such a method outside Stooges and this works in a test program just fine: def nextStooge(v:Stooges.Stooge):Stooges.Stooge = Stooges((v.id+1) % Stooges.values.size) What I'd really like is to add this method to Stooges and I have tried doing such a thing

Qt4 QSettings save enumeration value (for example Qt::CheckState)

末鹿安然 提交于 2019-12-10 17:45:26
问题 i wanna save state of QCheckBok in QSetting, i can cast its value to int but maybe exists more simple and proper method to do it? here is my code: QSetting setting; Qt::CheckState checkState; //... checkState = (Qt::CheckState)setting.value("checkState", Qt::Unchecked).toUInt(); //... setting.setValue("checkState", (uint)checkState); setting.sync(); 回答1: Firstly, try to avoid C-style casts. For example, replace the following line: checkState = (Qt::CheckState)setting.value("checkState", Qt:

how to define an enumeration inside a class and use it from the outside

老子叫甜甜 提交于 2019-12-10 13:00:51
问题 Just because I don't know exactly where to look this up in my c++ book, or on google. How do I actually define some enumerations(in this case { left=1, right=2, top=3, bottom=4 } ) inside a class. I want to be able to pass this enumeration as a parameter to member functions instead of an integer, therefore using the enumeration externally... Is there a way I can do this, or is there a better way I which I can make the enumeration specific to that class only? Here's the code that's not working

Is Vulkan's VkMemoryHeapFlagBits missing values?

ぃ、小莉子 提交于 2019-12-10 05:32:00
问题 At Vulkan specs 1.0.9 (pg. 180), we have the following: typedef struct VkMemoryHeap { VkDeviceSize size; VkMemoryHeapFlags flags; } VkMemoryHeap; and this description: • size is the total memory size in bytes in the heap. • flags is a bitmask of attribute flags for the heap. The bits specified in flags are: typedef enum VkMemoryHeapFlagBits { VK_MEMORY_HEAP_DEVICE_LOCAL_BIT = 0x00000001, } VkMemoryHeapFlagBits; But when I query VkPhysicalDeviceMemoryProperties I've got flags with zero values.

“if” statement vs OO Design

走远了吗. 提交于 2019-12-10 03:44:01
问题 I have enum say ErrorCodes that public enum ErrorCodes { INVALID_LOGIN(100), INVALID_PASSWORD(101), SESSION_EXPIRED(102) ...; private int errorCode; private ErrorCodes(int error){ this.errorCode = error; } //setter and getter and other codes } now I check my exception error codes with this error codes. I don't want to write if this do this, if this do this. How I can solve this problem (writing 10+ if blocks) Is there any design patter to that situation ? Thanks 回答1: As pointed out by Spoike,

Is it possible to guarantee the value of what ToString for an enum will be?

时间秒杀一切 提交于 2019-12-10 02:23:38
问题 The database I am working with currently has a varchar field, and in my code I want to map the potential values to a enumeration like: public enum UserStatus { Anonymous, Enrolled, SuperUser } At the database level for this column, there is a constrain on it where the value has to be: ANONYMOUS ENROLLED SUPERUSER Is it possible for me to do: UserStatus.SuperUser.ToString() And have that value be SUPERUSER, and this be consistant and not screw up down the road? 回答1: A better solution may be to

C++ “Floating Point Enum”

醉酒当歌 提交于 2019-12-09 13:05:14
问题 I am looking for a solution using the C++03 standard (I am constrained to using this version of the standard for several years yet). Solutions for C++11 are also welcome, but will not be "accepted" as the answer to this question. What is a simple, concise way that I can represent a set of related constant floating point values as a single type (similar to an enum) to ensure type-safety without incurring significant overhead and still allow me to operate on the values as floats directly? The

How can I use C# style enumerations in Ruby?

做~自己de王妃 提交于 2019-12-09 09:58:50
问题 I just want to know the best way to emulate a C# style enumeration in Ruby. 回答1: Specifically, I would like to be able to perform logical tests against the set of values given some variable. Example would be the state of a window: "minimized, maximized, closed, open" If you need the enumerations to map to values (eg, you need minimized to equal 0, maximised to equal 100, etc) I'd use a hash of symbols to values, like this: WINDOW_STATES = { :minimized => 0, :maximized => 100 }.freeze The

How to enumerate returned rows in SQL?

◇◆丶佛笑我妖孽 提交于 2019-12-09 05:09:15
问题 I was wondering if it would be possible to enumerate returned rows. Not according to any column content but just yielding a sequential integer index. E.g. select ?, count(*) as usercount from users group by age would return something along the lines: 1 12 2 78 3 4 4 42 it is for https://data.stackexchange.com/ 回答1: try: SELECT ROW_NUMBER() OVER(ORDER BY age) AS RowNumber ,count(*) as usercount from users group by age 回答2: If it's Oracle, use rownum . SELECT SOMETABLE.*, ROWNUM RN FROM

Looping through an enum, TypeScript and JQuery

旧街凉风 提交于 2019-12-08 16:47:34
问题 Hello im trying t develop a straight forward todo app using TypeScript and JQuery. I have an enum that lists task types: export enum TaskType { FrontEnd, BackEnd, Designer }; However looping through the emum using jquery.each or for loop, i get the following result, (values then indexes): FrontEnd, BackEnd, Designer, 0, 1, 2 The following is the code i loop through the enum: constructor(e?: Object) { var template = this.FormTemplate; $(e).append(template); var sel = template.find('select'); /