enumeration

Objective-C / C giving enums default values

I read somewhere about giving enums default values like so: typedef enum { MarketNavigationTypeNone = 0, MarketNavigationTypeHeirachy = 1, MarketNavigationTypeMarket = 2 } MarketNavigationLevelType; .. but i can't remember the value of doing this. If i don't give them default values - and then someone later on reorders the enum - wha...

GetFirstChild in win32 ?

Hello All, I use EnumChildWindows to get all the Child windows from the main HWND window , But i would like to get only the first child of the given HWND window. BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam) { // logic to call only once } Is it correct ? or any other simple way ? ~UK ...

Can the lock function be used to implement thread-safe enumeration?

I'm working on a thread-safe collection that uses Dictionary as a backing store. In C# you can do the following: private IEnumerable<KeyValuePair<K, V>> Enumerate() { if (_synchronize) { lock (_locker) { foreach (var entry in _dict) yield return entry; } } else { foreach (var...

What is the advantage of creating an enumerable object using to_enum in Ruby?

Hi, Why would you create a proxy reference to an object in Ruby, by using the to_enum method rather than just using the object directly? I cannot think of any practical use for this, trying to understand this concept & where someone might use it, but all the examples I have seen seem very trivial. For example, why use: "hello".enum_fo...

Enumerations and String values in ASP.NET

I'm looking for some best practice advice on enumerations and retrieving an associated string value. Given this: public enum Fruits { Apple, Orange, Grapefruit, Melon } What is the best way to get a related string value of the name? Eg. "Grapefruit", given that the string value may not match the representation in the e...

How is `toString` in `scala.Enumeration$Value` implemented?

I have an enum Fruit defined as: object Fruit extends Enumeration { val Apple, Banana, Cherry = Value } Now printing values of this enum, on Scala 2.7.x gives: scala> Fruit foreach println line1$object$$iw$$iw$Fruit(0) line1$object$$iw$$iw$Fruit(1) line1$object$$iw$$iw$Fruit(2) However the same operation on Scala 2.8 gives: scal...

Children in Enumeration

Hello I have a enumeration for elements in a JTree When I find some specific element in this JTree, I want to check it's children. Do the method children() in a Enumeration check it's grandcildren too? For example, let's supose this JTree, considering the identation as new levels of the tree: Fruits apple grape orange peach pinea...

Eclipse says I don't implement Enumeration, but I do

Goodmorning everybody, I'm having a little problem with a project for school. We are told to make an Iterator that implements Enumeration over a Hashmap. So i made this Enumeration: public Enumeration<Object> getEnumeration() { return new Enumeration<Object>() { private int itemsDone = 0; Collection<Lon...

Recursive Enumeration in Java

Hello everyone. I still have a question about Enumerations. Here's a quick sketch of the situation. I have a class Backpack that has a Hashmap content with as keys a variable of type long, and as value an ArrayList with Items. I have to write an Enumeration that iterates over the content of a Backpack. But here's the catch: in a Backp...

Problematic behavior of Linq Union?!

Hi, consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String> { "test", "t" }; IEnumerable<String> allLexicals = new List<String> { "test", "Test", "T", "t" }; IEnumerable<String> lexicals = new List<String> (); foreach (String s i...

How to enumerate returned rows in SQL?

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 http://odata.stackexchange.com/ ...

In which versions of ruby are external iterator speeds improved?

According to this rubyquiz, external iterators used to be slow, but are now faster. Is this an improvement only available in YARV (the C-based implementation of ruby 1.9), or is this also available in the C-based implementation of ruby 1.8.7? Also, does enum_for rely on external iterators? ...

Design guidelines for Enumeration

In one of the financial Winform projects , the application code will have to work with values such as currencies. In the object model that represents business entities , there are fields that need to hold currency values such as USD , EUR , etc. The set of values for this field will most probably be limited to one of the standard currenc...

Regular expression for matching a variety of types of numbered lists

I'd like to create a (PCRE) regular expression to match all commonly used numbered lists, and I'd like to share my thoughts and gather input on way to do this. I've defined 'lists' as the set of canonical Anglo-Saxon conventions, i.e. Numbers 1 2 3 1. 2. 3. 1) 2) 3) (1) (2) (3) 1.1 1.2 1.2.1 1.1. 1.2. 1.3. 1.1) 1.2) 1.3) (1.1) (1.2) (...

How to get Long/Int value of a enum set in Scala 2.8

In Scala 2.7, Enumeration provide Set32/Set64 to build enum set and easily get the bitwise value in Long/Int or build enum set back from a Long/Int value (which ease db storage). Scala 2.8 removed these classes. Is there a replacement in 2.8 lib? ...

Deleting registry key values

In MSDN it says that RegEnumValue should not be used when calling function that change the registry keys being enumerated. So does this also apply to deleting registry key values? Like this code does: if (RegOpenKeyEx(m_hkey,m_path.c_str(),0,KEY_ALL_ACCESS,&key) == ERROR_SUCCESS) { bool error=false; idx=0; while (RegEnumValue(k...

Fluent Nhibernate - Map many to many dictionary with enum key

I'm trying to do a mapping for the following classes: public class A { public virtual int Id { get; private set; } public virtual IDictionary<MyEnum, B> MyBValues { get; set; } } public class B { public virtual int Id { get; private set; } } public enum MyEnum { Value1, Value2, Value3 } I'd like the resulting tables to look...

Difficult exluding objects based on key while enumerating an NSMutableDictionary

I'm stumped. I have an NSMutableDictionary w/ nested dictionaries that I am enumerating through to create an Array of a particular key value in a nested dictionary, but I want to exlude two "keys". I am able to do it if I exclude one key, but as soon as I try to use the "||" or operator in my If statement it stops working and just adds ...

How to store string descriptions of enumeration values?

The application I'm working on has lots of enumerations. These values are generally selected from drop downs in the application. What is the generally accepted way of storing the string description of these values? Here is the current issue at hand: Public Enum MyEnum SomeValue = 1 AnotherValue = 2 ObsoleteValue = 3 YetAn...

Enumeration relying on integer boolean conversion

In my compiler project, I have an enumeration that goes like enum Result { No, Maybe, Yes }; I have put No explicitly at the first position, so that i can rely on the boolean evaluation to false. If my compiler is not sure about something, and has to wait for facts until runtime, its analysis functions will return Maybe. Used li...