Search Results

Search found 908 results on 37 pages for 'iterator'.

Page 8/37 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • ant: iterator over properties file

    - by scheibenkleister
    Hi, all my projects and their versions are defined in a properties file like this: ProjectNameA=0.0.1 ProjectNameB=1.4.2 I'd like to iterate over all projects and use there names and versions in an ant script. Right now, I read the entire properties file in help of the property task. Then I iterate over a given list in a for loop like this: <for list="ProjectNameA,ProjectNameB" param="project"> <sequential> <echo message="@{project} has version ${@{project}}" /> </sequential> </for> How can I avoid the duplication of the project names in the for loop. So basically iterate over each line and extract the name and the version of a project. Thanks.

    Read the article

  • Generate navigation from a multi-dimensional array

    - by rg88
    The question: How do I generate navigation, allowing for applying different classes to different sub-items, from a multi-dimensional array? Here is how I was doing it before I had any need for multi-level navigation: Home Pics About and was generated by calling nav(): function nav(){ $links = array( "Home" => "home.php", "Pics" => "pics.php", "About" => "about.php" ); $base = basename($_SERVER['PHP_SELF']); foreach($nav as $k => $v){ echo buildLinks($k, $v, $base); } } Here is buildLinks(): function buildLinks($name, $page, $selected){ if($selected == $page){ $theLink = "<li class=\"selected\"><a href=\"$page\">$name</a></li>\n"; } else { $thelink = "<li><a href=\"$page\">$name</a></li>\n"; } return $thelink; } My question, again: how would I achieve the following nav (and notice that the visible sub navigation elements are only present when on that specific page): Home something1 something2 Pics About and... Home Pics people places About What I've tried From looking at it it would seem that some iterator in the SPL would be a good fit for this but I'm not sure how to approach this. I have played around with RecursiveIteratorIterator but I'm not sure how to apply a different style to only the sub menu items and also how to only show these items if you are on the correct page. I built this array to test with but don't know how to work with the submenu1 items individually: $nav = array( array( "Home" => "home.php", "submenu1" => array( "something1"=>"something1.php", "something2" => "something2.php") ), array("Pics" => "pics.php"), array("About" => "about.php") ); The following will print out the lot in order but how do I apply, say a class name to the submenu1 items or only show them when the person is on, say, the "Home" page? $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($nav)); foreach($iterator as $key=>$value) { echo $key.' -- '.$value.'<br />'; }

    Read the article

  • Tree iterator, can you optimize this any further?

    - by Ron
    As a follow up to my original question about a small piece of this code I decided to ask a follow up to see if you can do better then what we came up with so far. The code below iterates over a binary tree (left/right = child/next ). I do believe there is room for one less conditional in here (the down boolean). The fastest answer wins! The cnt statement can be multiple statements so lets make sure this appears only once The child() and next() member functions are about 30x as slow as the hasChild() and hasNext() operations. Keep it iterative <-- dropped this requirement as the recursive solution presented was faster. This is C++ code visit order of the nodes must stay as they are in the example below. ( hit parents first then the children then the 'next' nodes). BaseNodePtr is a boost::shared_ptr as thus assignments are slow, avoid any temporary BaseNodePtr variables. Currently this code takes 5897ms to visit 62200000 nodes in a test tree, calling this function 200,000 times. void processTree (BaseNodePtr current, unsigned int & cnt ) { bool down = true; while ( true ) { if ( down ) { while (true) { cnt++; // this can/will be multiple statesments if (!current->hasChild()) break; current = current->child(); } } if ( current->hasNext() ) { down = true; current = current->next(); } else { down = false; current = current->parent(); if (!current) return; // done. } } }

    Read the article

  • Iterating multple lists consecutively (C++)

    - by Graham Rogers
    I have 3 classes, 2 inheriting from the other like so: class A { public: virtual void foo() {cout << "I am A!" << endl;} }; class B : public A { public: void foo() {cout << "B pretending to be A." << endl} void onlyBFoo() {cout << "I am B!" << endl} }; class C : public A { public: void foo() {cout << "C pretending to be A." << endl} void onlyCFoo() {cout << "I am C!" << endl} }; What I want to do is something like this: list<A> list_of_A; list<B> list_of_B; list<C> list_of_C; //put three of each class in their respective list for (list<B>::iterator it = list_of_B.begin(); it != list_of_B.end(); ++it) { (*it).onlyBFoo(); } for (list<C>::iterator it = list_of_C.begin(); it != list_of_C.end(); ++it) { (*it).foo(); } //This part I am not sure about for (list<A>::iterator it = list_of_all.begin(); it != list_of_all.end(); ++it) { (*it).foo(); } To output: I am B! I am B! I am B! I am C! I am C! I am C! I am A! I am A! I am A! B pretending to be A. B pretending to be A. B pretending to be A. C pretending to be A. C pretending to be A. C pretending to be A. Basically, sometimes I want to only loop the Bs and Cs so that I can use their methods, but sometimes I want to loop all of them so that I can use the same method from each i.e. iterate the As, then the Bs, then the Cs all in one loop. I thought of creating a separate list (like the code above) containing everything, but it would create lots of unnecessary maintenance, as I will be adding and removing every object from 2 lists instead of one.

    Read the article

  • C++ Iterator Pipelining Designs

    - by Kirakun
    Suppose we want to apply a series of transformations, int f1(int), int f2(int), int f3(int), to a list of objects. A naive way would be SourceContainer source; TempContainer1 temp1; transform(source.begin(), source.end(), back_inserter(temp1), f1); TempContainer2 temp2; transform(temp1.begin(), temp1.end(), back_inserter(temp2), f2); TargetContainer target; transform(temp2.begin(), temp2.end(), back_inserter(target), f3); This first solution is not optimal because of the extra space requirement with temp1 and temp2. So, let's get smarter with this: int f123(int n) { return f3(f2(f1(n))); } ... SourceContainer source; TargetContainer target; transform(source.begin(), source.end(), back_inserter(target), f123); This second solution is much better because not only the code is simpler but more importantly there is less space requirement without the intermediate calculations. However, the composition f123 must be determined at compile time and thus is fixed at run time. How would I try to do this efficiently if the composition is to be determined at run time? For example, if this code was in a RPC service and the actual composition--which can be any permutation of f1, f2, and f3--is based on arguments from the RPC call.

    Read the article

  • Eclipse C++ on WinXP - Type `::iterator' has not been declared

    - by redwolfe
    I'm new to C++/Eclipse. I'm trying to get it working to get a new perspective on a problem with a program I wrote in DevCPP. The program is simple and builds fine in DevCPP. In Eclipse, I get hundreds of errors like the one above. I assume the compiler can't see my include files. I've checked that the project settings - GCC C++ compiler - directories contains the location for my include files (D:\MinGW\include\c++\3.4.5). I've prowled around and tried to change 'Discovery Options' to 'GCC C++ Compiler' from 'GCC C Compiler' but it keeps changing back. I guess this is not the problem. Any help would be very welcome. I'm on a tight deadline with many interruptions and this is cracking me up.

    Read the article

  • Action Script 3.0 datatype to match C++ iterator? (Code convertion)

    - by user919496
    I am developing a game with Action Script 3.0 using Starling Framework, converting it from C++ C++ Code : for (std::vector<MyObject*>::iterator i = m_listEnemy->begin();i!= m_listEnemy->end();) { (*i)->update(dt); if ( (*i)->m_Hp <=0 ) { (*i)->release(); i = m_listEnemy->erase(i); continue; } i++; } MyObject is the class. What Action Script 3.0 data type matches the C++ iterator? Also , how can I convert this C++ code to Action Script 3.0 code? Thanks in advance!

    Read the article

  • Can't access a map member from a pointer

    - by fjfnaranjo
    Hi. That's my first question :) I'm storing the configuration of my program in a Group->Key->Value form, like the old INIs. I'm storing the information in a pair of structures. First one, I'm using a std::map with string+ptr for the groups info (the group name in the string key). The second std::map value is a pointer to the sencond structure, a std::list of std::maps, with the finish Key->Value pairs. The Key-Value pairs structure is created dynamically, so the config structure is: std::map< std::string , std::list< std::map<std::string,std::string> >* > lv1; Well, I'm trying to implement two methods to check the existence of data in the internal config. The first one, check the existence of a group in the structure: bool isConfigLv1(std::string); bool ConfigManager::isConfigLv1(std::string s) { return !(lv1.find(s)==lv1.end()); } The second method, is making me crazy... It check the existence for a key inside a group. bool isConfigLv2(std::string,std::string); bool ConfigManager::isConfigLv2(std::string s,std::string d) { if(!isConfigLv1(s)) return false; std::map< std::string , std::list< std::map<std::string,std::string> >* >::iterator it; std::list< std::map<std::string,std::string> >* keyValue; std::list< std::map<std::string,std::string> >::iterator keyValueIt; it = lv1.find(s); keyValue = (*it).second; for ( keyValueIt = keyValue->begin() ; keyValueIt != keyValue->end() ; keyValueIt++ ) if(!((*keyValueIt).second.find(d)==(*keyValueIt).second.end())) return true; return false; } I don't understand what is wrong. The compiler says: ConfigManager.cpp||In member function ‘bool ConfigManager::isConfigLv2(std::string, std::string)’:| ConfigManager.cpp|(line over return true)|error: ‘class std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >’ has no member named ‘second’| But it has to have the second member, because it's a map iterator... Any suggestion about what's happening? Sorry for my English :P, and consider I'm doing it as a exercise, I know there are a lot of cool configuration managers.

    Read the article

  • How does the PHP IteratorIterator class work?

    - by WilliamMartin
    Try as I might I cannot get my head around what the IteratorIterator class actually does. I understand that classes can implement Traversable so the engine knows it can loop using foreach and I realise that IteratorIterator is supposed to convert anything that is Traversable into an Iterator but I cannot for the life of me understand how. Take for example, the PDOStatement class; how would the standard Iterator methods (next, key, rewind, etc) be implemented to allow iteration over a PDOStatement? Sorry if my question is unclear, I am just struggling to grasp the exact reason for this class and the documentation on it is scant. Thanks, Will Update: Going through the phpt files, I found one test which uses IteratorIterator: <?php $root = simplexml_load_string('<?xml version="1.0"?> <root> <child>Hello</child> <child>World</child> </root> '); foreach (new IteratorIterator($root->child) as $child) { echo $child."\n"; } ?> The expected output is: Hello World I don't really follow how the IteratorIterator construct takes $root-child as an argument and how it manages to iterate over the child elements.

    Read the article

  • How do you use boost iterators

    - by Neil G
    It worked, and then I added the typedefs so that I could have a const_sparse_iterator as well. Now, when I compile this and try to use sparse_iterator, it says: /Users/neilrg/nn/src/./core/sparse_vector.h:331: error: invalid use of incomplete type 'struct sparse_vector<A>::sparse_iterator' Here's the code. More code here. tempalte<typename T> class sparse_vector { // There is more code at my previous question, but this might be enough...? private: template<typename base_type> class sparse_iterator_private : public boost::iterator_adaptor< sparse_iterator_private<base_type> // Derived , base_type // Base , value_type // Value , boost::random_access_traversal_tag // CategoryOrTraversal > { private: struct enabler {}; // a private type avoids misuse public: sparse_iterator_private() : sparse_iterator_private<base_type>::iterator_adaptor_(0) {} explicit sparse_iterator_private(typename array_type::iterator&& p) : sparse_iterator_private<base_type>::iterator_adaptor_(p) {} private: friend class boost::iterator_core_access; reference dereference() const { return this->base()->value; } }; public: typedef sparse_iterator_private<typename array_type::iterator> sparse_iterator; typedef sparse_iterator_private<typename array_type::const_iterator> const_sparse_iterator; };

    Read the article

  • How to iterate properly across a const set?

    - by Jared
    I'm working on a program that's supposed to represent a graph. My issue is in my printAdjacencyList function. Basically, I have a Graph ADT that has a member variable "nodes", which is a map of the nodes of that graph. Each Node has a set of Edge* to the edges it is connected to. I'm trying to iterate across each node in the graph and each edge of a node. void MyGraph::printAdjacencyList() { std::map<std::string, MyNode*>::iterator mit; std::set<MyEdge*>::iterator sit; for (mit = nodes.begin(); mit != nodes.end(); mit++ ) { std::cout << mit->first << ": {"; const std::set<MyEdge*> edges = mit->second->getEdges(); for (sit = edges.begin(); sit != edges.end(); sit++) { std::pair<MyNode*, MyNode*> edgeNodes = *sit->getEndpoints(); } } std::cout << " }" << std::endl; } getEdges is declared as: const std::set<MyEdge*>& getEdges() { return edges; }; and get Endpoints is declared as: const std::pair<MyNode*, MyNode*>& getEndpoints() { return nodes; }; The compiler error I'm getting is: MyGraph.cpp:63: error: request for member `getEndpoints' in `*(&sit)->std::_Rb_tree_const_iterator<_Tp>::operator-> [with _Tp = MyEdge*]()', which is of non-class type `MyEdge* const' MyGraph.cpp:63: warning: unused variable 'edgeNodes' I have figured out that this probably means I'm misusing const somewhere, but I can't figure out where for the life of me. Any information would be appreciated. Thanks!

    Read the article

  • C++ STL question related to insert iterators and sets

    - by rshepherd
    #include #include #include #include using namespace std; class MyContainer { public: string value; MyContainer& operator=(const string& s) { this->value = s; return *this; } }; int main() { list<string> strings; strings.push_back("0"); strings.push_back("1"); strings.push_back("2"); set<MyContainer> containers; copy(strings.begin(), strings.end(), inserter(containers, containers.end())); } The preceeding code does not compile. In typical STL style the error output is verbose and difficult to understand. The key part seems to be this... /usr/include/c++/4.4/bits/stl_algobase.h:313: error: no match for ‘operator=’ in ‘__result.std::insert_iterator::operator* [with _Container = std::set, std::allocator ]() = __first.std::_List_iterator::operator* [with _Tp = std::basic_string, std::allocator ]()’ ...which I interpet to mean that the assignment operator needed is not defined. I took a look at the source code for insert_iterator and noted that it has overloaded the assignment operator. The copy algorithm must uses the insert iterators overloaded assignment operator to do its work(?). I guess that because my input iterator is on a container of strings and my output iterator is on a container of MyContainers that the overloaded insert_iterator assignment operator can no longer work. This is my best guess, but I am probably wrong. So, why exactly does this not work and how can I accomplish what I am trying to do?

    Read the article

  • Is Multiple Iterators is possible in php?

    - by artvolk
    Good day! I know that C# allows multiple iterators using yield, like described here: http://stackoverflow.com/questions/1754041/is-multiple-iterators-is-possible-in-c In PHP there is and Iterator interface. Is it possible to implement more than one iteration scenario for a class?

    Read the article

  • Incorrect data when passing pointer a list of pointers to a function. (C++)

    - by Phil Elm
    I'm writing code for combining data received over multiple sources. When the objects received (I'll call them MyPacket for now), they are stored in a standard list. However, whenever I reference the payload size of a partial MyPacket, the value shows up as 1 instead of the intended size. Here's the function code: MyPacket* CombinePackets(std::list<MyPacket*>* packets, uint8* current_packet){ uint32 total_payload_size = 0; if(packets->size() <= 0) return NULL; //For now. std::list<MyPacket*>::iterator it = packets->begin(); //Some minor code here, not relevant to the problem. for(uint8 index = 0; index < packets->size(); index++){ //(*it)->GetPayloadSize() returns 1 when it should show 1024. I've tried directly accessing the variable and more, but I just can't get it to work. total_payload_size += (*it)->GetPayloadSize(); cout << "Adding to total payload size value: " << (*it)->GetPayloadSize() << endl; std::advance(it,1); } MyPacket* packet = new MyPacket(); //Byte is just a typedef'd unsigned char. packet->payload = (byte) calloc(total_payload_size, sizeof(byte)); packet->payload_size = total_payload_size; it = packets->begin(); //Go back to the beginning again. uint32 big_payload_index = 0; for(uint8 index = 0; index < packets->size(); index++){ if(current_packet != NULL) *current_packet = index; for(uint32 payload_index = 0; payload_index < (*it)->GetPayloadSize(); payload_index++){ packet->payload[big_payload_index] = (*it)->payload[payload_index]; big_payload_index++; } std::advance(it,1); } return packet; } //Calling code std::list<MyPacket*> received = std::list<MyPacket*>(); //The code that fills it is here. std::list<MyPacket*>::iterator it = received.begin(); cout << (*it)->GetPayloadSize() << endl; // Outputs 1024 correctly! MyPacket* final = CombinePackets(&received,NULL); cout << final->GetPayloadSize() << endl; //Outputs 181, which happens to be the number of elements in the received list. So, as you can see above, when I reference (*it)-GetPayloadSize(), it returns 1 instead of the intended 1024. Can anyone see the problem and if so, do you have an idea on how to fix this? I've spent 4 hours searching and trying new solutions, but they all keep returning 1... EDIT:

    Read the article

  • Number of lines in csv.DictReader

    - by Alan Harris-Reid
    Hi there, I have a csv DictReader object (using Python 3.1), but I would like to know the number of lines/rows contained in the reader before I iterate through it. Something like as follows... myreader = csv.DictReader(open('myFile.csv', newline='')) totalrows = ? rowcount = 0 for row in myreader: rowcount +=1 print("Row %d/%d" % (rowcount,totalrows)) I know I could get the total by iterating through the reader, but then I couldn't run the 'for' loop. I could iterate through a copy of the reader, but I cannot find how to copy an iterator. I could also use totalrows = len(open('myFile.csv').readlines()) but that seems an unnecessary re-opening of the file. I would rather get the count from the DictReader if possible. Any help would be appreciated. Alan

    Read the article

  • Are Multiple Iterators possible in php?

    - by artvolk
    Good day! I know that C# allows multiple iterators using yield, like described here: http://stackoverflow.com/questions/1754041/is-multiple-iterators-is-possible-in-c In PHP there is and Iterator interface. Is it possible to implement more than one iteration scenario for a class? More details (EDIT): For example I have class TreeNode implementing single tree node. The whole tree can be expressed using only one this class. I want to provide iterators for iterating all direct and indirect children of current node, for example using BreadthFirst or DepthFirst order. I can implement this Iterators as separate classes but doing so I need that tree node should expose it's children collection as public. C# pseudocode: public class TreeNode<T> { ... public IEnumerable<T> DepthFirstEnumerator { get { // Some tree traversal using 'yield return' } } public IEnumerable<T> BreadthFirstEnumerator { get { // Some tree traversal using 'yield return' } } }

    Read the article

  • python iterators and thread-safety

    - by Igor
    I have a class which is being operated on by two functions. One function creates a list of widgets and writes it into the class: def updateWidgets(self): widgets = self.generateWidgetList() self.widgets = widgets the other function deals with the widgets in some way: def workOnWidgets(self): for widget in self.widgets: self.workOnWidget(widget) each of these functions runs in it's own thread. the question is, what happens if the updateWidgets() thread executes while the workOnWidgets() thread is running? I am assuming that the iterator created as part of the for...in loop will keep some kind of reference to the old self.widgets object? So I will finish iterating over the old list... but I'd love to know for sure.

    Read the article

  • just-in-time list

    - by intuited
    I'd like to know if there is a class available, either in the standard library or in pypi, that fits this description. The constructor would take an iterator. It would implement the container protocol (ie _getitem_, _len_, etc), so that slices, length, etc., would work. In doing so, it would iterate and retain just enough values from its constructor argument to provide whatever information was requested. So if jitlist[6] was requested, it would call self.source.next() 7 times, save those elements in its list, and return the last one. This would allow downstream code to use it as a list, but avoid unnecessarily instantiating a list for cases where list functionality was not needed, and avoid allocating memory for the entire list if only a few members ended up being requested. It seems like a pretty easy one to write, but it also seems useful enough that it's likely that someone would have already made it available in a module.

    Read the article

  • Are there any open source SimpleTest Test Cases that test PHP SPL interfaces

    - by JW
    I have quite a few objects in my system that implement the PHP SPL Iterator interface. As I write them I also write tests. I know that writing tests is generally NOT a cut 'n paste job. But, when it comes to testing classes that implement Standard PHP Library interfaces, surely it makes sense to have a few script snippets that can be borrowed and dropped in to a Test class - purely to test that particular interface. It seems sensible to have these publicly available. So, I was wondering if you knew of any?

    Read the article

  • iteration on numbers with no 2 same digits

    - by rahmivolkan
    I dont know if it is asked (I couldn't find any). I want to iterate on this kind of numbers implemented on array; int a[10]; int i = 0; for( ; i < 10; i++ ) a[i] = i+1; now the array has "1 2 3 4 5 6 7 8 9 10" and I want to get "1 2 3 4 5 6 7 8 10 9" and then "1 2 3 4 5 6 7 9 8 10" "1 2 3 4 5 6 7 9 10 8" . . . . I tried to get an algorithm but I couldn't figure it out. Is there an easy way to implement "next" iterator for this kind of problems? Thanks in advance

    Read the article

  • Python method to remove iterability

    - by Debilski
    Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with try: iter(arg). Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable input, it is easy to do: I’ll just wrap it with a tuple. What do I do when I want to pass an iterable (a string for example) but want the function to take it as if it’s non-iterable? E.g. make that iter(str) fails.

    Read the article

  • String vectors not working as expected with newline and iterators? (C++)

    - by kevin
    I have a text file made of 3 lines: Line 1 Line 3 (Line 1, a blank line, and Line 3) vector<string> text; vector<string>::iterator it; ifstream file("test.txt"); string str; while (getline(file, str)) { if (str.length() == 0) str = "\n"; // since getline discards the newline character, replacing blank strings with newline text.push_back(str); } // while for (it=text.begin(); it < text.end(); it++) cout << (*it); Prints out: Line 1 Line 3 I'm not sure why the string with only a newline was not printed out. Any help would be appreciated. Thanks.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >