enumeration

How to enumerate all available network interfaces? [duplicate]

一笑奈何 提交于 2019-11-30 02:57:09
问题 This question already has an answer here : How to enumerate network adapters and get their MAC addresses in Win32 API C++? (1 answer) Closed 2 years ago . How to enumerate all network interfaces currently available on the computer (including virtual, non-connected, loopback etc)? I need to know their IP4/6, Mask, Gateway, DNS, WINS etc Language: C++, WinAPI System: Windows 2000 and higher (including Win7) 回答1: Have a look at http://www.codeproject.com/KB/IP/netcfg.aspx. It's a giant example

How to read a properties file in java in the original order [duplicate]

不想你离开。 提交于 2019-11-30 02:04:43
This question already has an answer here: Pulling values from a Java Properties file in order? 15 answers I need to read a properties file and generate a Properties class in Java. I do so by using: Properties props = new Properties(); props.load(new FileInputStream(args[0])); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { } However, the properties returned by props.propertyName is not in the order of the original properties file. I understand that Properties are just old fashioned, non-generified Hashtables. I'm looking for a work around. Any idea? Thank you! You may want

Treat Enumeration<T> as Iterator<T>

我的未来我决定 提交于 2019-11-30 01:47:05
问题 I have a class that implements the Enumeration<T> interface, but Java's foreach loop requires the Iterator<T> interface. Is there an Enumeration to Iterator Adapter in Java's standard library? 回答1: You need a so called "Adapter", to adapt the Enumeration to the otherwise incompatible Iterator . Apache commons-collections has EnumerationIterator. The usage is: Iterator iterator = new EnumerationIterator(enumeration); 回答2: If you just want something to iterate over in a for-each loop (so an

Strange “Collection was modified after the enumerator was instantiated” exception

安稳与你 提交于 2019-11-30 01:43:26
问题 Perhaps someone can point me in the correct direction, because I'm completely stumped on this. I have a function that simply prints out a LinkedList of classes: LinkedList<Component> components = new LinkedList<Component>(); ... private void PrintComponentList() { Console.WriteLine("---Component List: " + components.Count + " entries---"); foreach (Component c in components) { Console.WriteLine(c); } Console.WriteLine("------"); } The Component object actually has a custom ToString() call as

eliminating duplicate Enum code

陌路散爱 提交于 2019-11-30 00:09:34
I have a large number of Enums that implement this interface: /** * Interface for an enumeration, each element of which can be uniquely identified by it's code */ public interface CodableEnum { /** * Get the element with a particular code * @param code * @return */ public CodableEnum getByCode(String code); /** * Get the code that identifies an element of the enum * @return */ public String getCode(); } A typical example is: public enum IMType implements CodableEnum { MSN_MESSENGER("msn_messenger"), GOOGLE_TALK("google_talk"), SKYPE("skype"), YAHOO_MESSENGER("yahoo_messenger"); private final

Objective C — What is the fastest and most efficient way to enumerate an array?

让人想犯罪 __ 提交于 2019-11-29 21:32:52
Edit I read through some articles on blocks and fast enumeration and GCD and the like. @Bbum, who's written many articles on the subject of GCD and blocks, says that the block enumeration methods are always as fast or faster than the fast enumeration equivalents. You can read his reasoning here . While this has been a fascinating, intellectual conversation, I agree with those who said that it really depends on the task at hand. I have some tasks to accomplish and I need them done fast, cheap, and efficiently. Apple gives us many choices for how we want to enumerate an array, but I'm not sure

What is thread safe (C#) ? (Strings, arrays, … ?)

混江龙づ霸主 提交于 2019-11-29 21:30:18
I'm quite new to C# so please bear with me. I'm a bit confused with the thread safety. When is something thread safe and when something isn't? Is reading (just reading from something that was initialized before) from a field always thread safe? //EXAMPLE RSACryptoServiceProvider rsa = new RSACrytoServiceProvider(); rsa.FromXmlString(xmlString); //Is this thread safe if xml String is predifined //and this code can be called from multiple threads? Is accessing an object from an array or list always thread safe (in case you use a for loop for enumeration)? //EXAMPLE (a is local to thread, array

Is there a predefined enumeration for Month in the .NET library?

人盡茶涼 提交于 2019-11-29 20:47:20
I'm looking to see if there is an official enumeration for months in the .net framework. It seems possible to me that there is one, because of how common the use of month is, and because there are other such enumerations in the .net framework. For instance, there is an enumeration for the days in the week, System.DayOfWeek, which includes Monday, Tuesday, etc.. I'm wondering if there is one for the months in the year, i.e. January, February, etc? Does anyone know? Andy Mikula There isn't, but if you want the name of a month you can use: CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName

How to use std::foreach with parameters/modification

馋奶兔 提交于 2019-11-29 20:38:48
I've found myself writing for(int i=0;i<myvec.size();i++) myvec[i]->DoWhatever(param); a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things like for(int i=0;i<myvec.size();i++) if(myvec[i]->IsOK()) myvec[i]->DoWhatever(param); and I'd like to rewrite that guy too. Any thoughts? Oh, also, for various reasons, I don't want to use boost. #include <vector> #include <algorithm> #include <functional> class X { public: void doWhat(int x) {} bool IsOK() const {return true;} }; class CallWhatIfOk {

What is the best way to handle constants in Ruby when using Rails?

喜夏-厌秋 提交于 2019-11-29 19:36:38
I have some constants that represent the valid options in one of my model's fields. What's the best way to handle these constants in Ruby? Codebeef You can use an array or hash for this purpose (in your environment.rb): OPTIONS = ['one', 'two', 'three'] OPTIONS = {:one => 1, :two => 2, :three => 3} or alternatively an enumeration class, which allows you to enumerate over your constants as well as the keys used to associate them: class Enumeration def Enumeration.add_item(key,value) @hash ||= {} @hash[key]=value end def Enumeration.const_missing(key) @hash[key] end def Enumeration.each @hash