Search Results

Search found 6580 results on 264 pages for 'boost foreach'.

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

  • Invalid argument for foreach()

    - by johnny-kessel
    Error I'm receiving Invalid argument supplied for foreach() The offending portions is this: foreach($subs[$id] as $id2 => $data2) Strange cause I'm using the same construct elsewhere and it works fine.. I'm using it to generate sub-categories and it works but I want to get rid of the error This is more context foreach($parents as $id => $data) { if($x == 0) { $html .= "<tr width='25%' class='row2'>"; } $shtml = ""; $i = 0; ***foreach($subs[$id] as $id2 => $data2)*** { $i++; if($i == 15) { $shtml .= $this->ipsclass->compiled_templates[ 'skin_businesses' ]->portal_categories_sub_row( $id2, $data2['cat_name'], 1 ) . ""; break; } else $shtml .= $this->ipsclass->compiled_templates[ 'skin_businesses' ]->portal_categories_sub_row( $id2, $data2['cat_name'], 0 ) . ""; }

    Read the article

  • Linker Issues with boost::thread under linux using Eclipse and CMake

    - by OcularProgrammer
    I'm in the process of attempting to port some code across from PC to Ubuntu, and am having some issues due to limited experience developing under linux. We use CMake to generate all our build stuff. Under windows I'm making VS2010 projects, and under Linux I'm making Eclipse projects. I've managed to get my OpenCV stuff ported across successfully, but am having major headaches trying to port my threaded boost apps. Just so we're clear, the steps I have followed so-far on a clean Ubuntu 12 installation. (I've done 2 clean re-installs to try and fix potential library cock-ups, now I'm just giving up and asking): Install Eclipse and Eclipse CDT using my package manager Install CMake and CMake Gui using my package manager Install libboost-all-dev using my package manager So-far that's all I've done. I can create the eclipse project using CMake with no errors, so CMake is successfully finding my boost install. When I try and build through eclipse is when I get issues; The app I'm attempting to build uses boost::asio for some UDP I/O and boost::thread to create worker threads for the asio I/O services. I can successfully compile each module, but when I come to link I get spammed with errors such as: /usr/bin/c++ CMakeFiles/RE05DevelopmentDemo.dir/main.cpp.o CMakeFiles/RE05DevelopmentDemo.dir/RE05FusionListener/RE05FusionListener.cpp.o CMakeFiles/RE05DevelopmentDemo.dir/NewEye/NewEye.cpp.o -o RE05DevelopmentDemo -rdynamic -Wl,-Bstatic -lboost_system-mt -lboost_date_time-mt -lboost_regex-mt -lboost_thread-mt -Wl,-Bdynamic /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `void boost::call_once<void (*)()>(boost::once_flag&, void (*)()) [clone .constprop.98]': make[2]: Leaving directory `/home/david/Code/Build/Support/RE05DevDemo' (.text+0xc8): undefined reference to `pthread_key_create' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `boost::this_thread::interruption_enabled()': (.text+0x540): undefined reference to `pthread_getspecific' make[1]: Leaving directory `/home/david/Code/Build/Support/RE05DevDemo' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()': (.text+0x570): undefined reference to `pthread_getspecific' /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libboost_thread-mt.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()': (.text+0x59f): undefined reference to `pthread_getspecific' Some Gotchas that I have collected from other StackOverflow posts and have already checked: The boost libs are all present at /usr/lib I am not getting any compile errors for inability to find the boost headers, so they must be getting found. I am trying to link statically, but I believe eclipse should be passing the correct arguments to make that happen since my CMakeLists.txt includes SET(Boost_USE_STATIC_LIBS ON) I'm officially out of ideas here, I have tried doing local builds of boost and a bunch of other stuff with no more success. I even re-installed Ubuntu to ensure I haven't completely fracked the libs directories and links with multiple weird versions or anything else. Any help would be muchly appreciated.

    Read the article

  • Using concurrently 2 versions of boost

    - by idimba
    I'm using RHEL 5.3, which is shipped with gcc 4.1.2 and boost 1.33. There're some features I want, that are missing in the boost 1.33. Therefore the thought was to upgrade to fresh boost release 1.43. Is it possible to use concurrently some header-only library(s) from boost 1.43 and the rest from 1.33? For example I want to use unorded_map, which is missing in boost 1.33. Is it possible to use concurrently binary boost libraries from different releases?

    Read the article

  • Help with Boost Grammar

    - by Decmanc04
    I have been using the following win32 console code to try to parse a B Machine Grammar embedded within C++ using Boost Spirit grammar template. I am a relatively new Boost user. The code compiles, but when I run the .exe file produced by VC++2008, the program partially parses the input file. I believe the problem is with my grammar definition or the functions attached as semantic atctions. The code is given below: // BIFAnalyser.cpp : Defines the entry point for the console application. // // /*============================================================================= Copyright (c) Temitope Jos Onunkun 2010 http://www.dcs.kcl.ac.uk/pg/onun/ Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ //////////////////////////////////////////////////////////////////////////// // // // B Machine parser using the Boost "Grammar" and "Semantic Actions". // // // //////////////////////////////////////////////////////////////////////////// #include <boost/spirit/core.hpp> #include <boost/tokenizer.hpp> #include <iostream> #include <string> #include <fstream> #include <vector> #include <utility> /////////////////////////////////////////////////////////////////////////////////////////// using namespace std; using namespace boost::spirit; /////////////////////////////////////////////////////////////////////////////////////////// // // Semantic actions // //////////////////////////////////////////////////////////////////////////// vector<string> strVect; namespace { //semantic action function on individual lexeme void do_noint(char const* str, char const* end) { string s(str, end); if(atoi(str)) { ; } else { strVect.push_back(s); cout << "PUSH(" << s << ')' << endl; } } //semantic action function on addition of lexemes void do_add(char const*, char const*) { cout << "ADD" << endl; for(vector<string>::iterator vi = strVect.begin(); vi < strVect.end(); ++vi) cout << *vi << " "; } //semantic action function on subtraction of lexemes void do_subt(char const*, char const*) { cout << "SUBTRACT" << endl; for(vector<string>::iterator vi = strVect.begin(); vi < strVect.end(); ++vi) cout << *vi << " "; } //semantic action function on multiplication of lexemes void do_mult(char const*, char const*) { cout << "\nMULTIPLY" << endl; for(vector<string>::iterator vi = strVect.begin(); vi < strVect.end(); ++vi) cout << *vi << " "; cout << "\n"; } //semantic action function on division of lexemes void do_div(char const*, char const*) { cout << "\nDIVIDE" << endl; for(vector<string>::iterator vi = strVect.begin(); vi < strVect.end(); ++vi) cout << *vi << " "; } //semantic action function on simple substitution void do_sSubst(char const* str, char const* end) { string s(str, end); //use boost tokenizer to break down tokens typedef boost::tokenizer<boost::char_separator<char> > Tokenizer; boost::char_separator<char> sep("-+/*:=()"); // default char separator Tokenizer tok(s, sep); Tokenizer::iterator tok_iter = tok.begin(); pair<string, string > dependency; //create a pair object for dependencies //save first variable token in simple substitution dependency.first = *tok.begin(); //create a vector object to store all tokens vector<string> dx; // for( ; tok_iter != tok.end(); ++tok_iter) //save all tokens in vector { dx.push_back(*tok_iter ); } vector<string> d_hat; //stores set of dependency pairs string dep; //pairs variables as string object for(int unsigned i=1; i < dx.size()-1; i++) { dependency.second = dx.at(i); dep = dependency.first + "|->" + dependency.second + " "; d_hat.push_back(dep); } cout << "PUSH(" << s << ')' << endl; for(int unsigned i=0; i < d_hat.size(); i++) cout <<"\n...\n" << d_hat.at(i) << " "; cout << "\nSIMPLE SUBSTITUTION\n"; } //semantic action function on multiple substitution void do_mSubst(char const* str, char const* end) { string s(str, end); //use boost tokenizer to break down tokens typedef boost::tokenizer<boost::char_separator<char> > Tok; boost::char_separator<char> sep("-+/*:=()"); // default char separator Tok tok(s, sep); Tok::iterator tok_iter = tok.begin(); // string start = *tok.begin(); vector<string> mx; for( ; tok_iter != tok.end(); ++tok_iter) //save all tokens in vector { mx.push_back(*tok_iter ); } mx.push_back("END\n"); //add a marker "end" for(unsigned int i=0; i<mx.size(); i++) { // if(mx.at(i) == "END" || mx.at(i) == "||" ) // break; // else if( mx.at(i) == "||") // do_sSubst(str, end); // else // { // do_sSubst(str, end); // } cout << "\nTokens ... " << mx.at(i) << " "; } cout << "PUSH(" << s << ')' << endl; cout << "MULTIPLE SUBSTITUTION\n"; } } //////////////////////////////////////////////////////////////////////////// // // Simple Substitution Grammar // //////////////////////////////////////////////////////////////////////////// // Simple substitution grammar parser with integer values removed struct Substitution : public grammar<Substitution> { template <typename ScannerT> struct definition { definition(Substitution const& ) { multi_subst = (simple_subst [&do_mSubst] >> +( str_p("||") >> simple_subst [&do_mSubst]) ) ; simple_subst = (Identifier >> str_p(":=") >> expression)[&do_sSubst] ; Identifier = alpha_p >> +alnum_p//[do_noint] ; expression = term >> *( ('+' >> term)[&do_add] | ('-' >> term)[&do_subt] ) ; term = factor >> *( ('*' >> factor)[&do_mult] | ('/' >> factor)[&do_div] ) ; factor = lexeme_d[( (alpha_p >> +alnum_p) | +digit_p)[&do_noint]] | '(' >> expression >> ')' | ('+' >> factor) ; } rule<ScannerT> expression, term, factor, Identifier, simple_subst, multi_subst ; rule<ScannerT> const& start() const { return multi_subst; } }; }; //////////////////////////////////////////////////////////////////////////// // // Main program // //////////////////////////////////////////////////////////////////////////// int main() { cout << "************************************************************\n\n"; cout << "\t\t...Machine Parser...\n\n"; cout << "************************************************************\n\n"; // cout << "Type an expression...or [q or Q] to quit\n\n"; //prompt for file name to be input cout << "Please enter a filename...or [q or Q] to quit:\n\n "; char strFilename[256]; //file name store as a string object cin >> strFilename; ifstream inFile(strFilename); // opens file object for reading //output file for truncated machine (operations only) Substitution elementary_subst; // Simple substitution parser object string str, next; // inFile.open(strFilename); while (inFile >> str) { getline(cin, next); str += next; if (str.empty() || str[0] == 'q' || str[0] == 'Q') break; parse_info<> info = parse(str.c_str(), elementary_subst, space_p); if (info.full) { cout << "\n-------------------------\n"; cout << "Parsing succeeded\n"; cout << "\n-------------------------\n"; } else { cout << "\n-------------------------\n"; cout << "Parsing failed\n"; cout << "stopped at: \": " << info.stop << "\"\n"; cout << "\n-------------------------\n"; } } cout << "Please enter a filename...or [q or Q] to quit\n"; cin >> strFilename; return 0; } The contents of the file I tried to parse, which I named "mf7.txt" is given below: debt:=(LoanRequest+outstandingLoan1)*20 || newDebt := loanammount-paidammount The output when I execute the program is: ************************************************************ ...Machine Parser... ************************************************************ Please enter a filename...or [q or Q] to quit: c:\tplat\mf7.txt PUSH(LoanRequest) PUSH(outstandingLoan1) ADD LoanRequest outstandingLoan1 MULTIPLY LoanRequest outstandingLoan1 PUSH(debt:=(LoanRequest+outstandingLoan1)*20) ... debt|->LoanRequest ... debt|->outstandingLoan1 SIMPLE SUBSTITUTION Tokens ... debt Tokens ... LoanRequest Tokens ... outstandingLoan1 Tokens ... 20 Tokens ... END PUSH(debt:=(LoanRequest+outstandingLoan1)*20) MULTIPLE SUBSTITUTION ------------------------- Parsing failedstopped at: ": " ------------------------- My intention is to capture only the variables in the file, which I managed to do up to the "||" string. Clearly, the program is not parsing beyond the "||" string in the input file. I will appreciate assistance to fix the grammar. SOS, please.

    Read the article

  • Boost Thread Synchronization

    - by Dave18
    I don't see synchronized output when i comment the the line wait(1) in thread(). can I make them run at the same time (one after another) without having to use 'wait(1)'? #include <boost/thread.hpp> #include <iostream> void wait(int seconds) { boost::this_thread::sleep(boost::posix_time::seconds(seconds)); } boost::mutex mutex; void thread() { for (int i = 0; i < 100; ++i) { wait(1); mutex.lock(); std::cout << "Thread " << boost::this_thread::get_id() << ": " << i << std::endl; mutex.unlock(); } } int main() { boost::thread t1(thread); boost::thread t2(thread); t1.join(); t2.join(); }

    Read the article

  • Trying to use boost lambda, but my code won't compile

    - by hamishmcn
    Hi, I am trying to use boost lambda to avoid having to write trivial functors. For example, I want to use the lambda to access a member of a struct or call a method of a class, eg: #include <vector> #include <utility> #include <algorithm> #include <boost/lambda/lambda.hpp> using namespace std; using namespace boost::lambda; vector< pair<int,int> > vp; vp.push_back( make_pair<int,int>(1,1) ); vp.push_back( make_pair<int,int>(3,2) ); vp.push_back( make_pair<int,int>(2,3) ); sort(vp.begin(), vp.end(), _1.first > _2.first ); When I try and compile this I get the following errors: error C2039: 'first' : is not a member of 'boost::lambda::lambda_functor<T>' with [ T=boost::lambda::placeholder<1> ] error C2039: 'first' : is not a member of 'boost::lambda::lambda_functor<T>' with [ T=boost::lambda::placeholder<2> ] Since vp contains pair<int,int> I thought that _1.first should work. What I am doing wrong?

    Read the article

  • boost::asio::async_resolve Problem

    - by Moo-Juice
    Hi All, I'm in the process of constructing a Socket class that uses boost::asio. To start with, I made a connect method that took a host and a port and resolved it to an IP address. This worked well, so I decided to look in to async_resolve. However, my callback always gets an error code of 995 (using the same destination host/port as when it worked synchronously). code: Function that starts the resolution: // resolve a host asynchronously template<typename ResolveHandler> void resolveHost(const String& _host, Port _port, ResolveHandler _handler) const { boost::asio::ip::tcp::endpoint ret; boost::asio::ip::tcp::resolver::query query(_host, boost::lexical_cast<std::string>(_port)); boost::asio::ip::tcp::resolver r(m_IOService); r.async_resolve(query, _handler); }; // eo resolveHost Code that calls this function: void Socket::connect(const String& _host, Port _port) { // Anon function for resolution of the host-name and asynchronous calling of the above auto anonResolve = [this](const boost::system::error_code& _errorCode, boost::asio::ip::tcp::resolver_iterator _epIt) { // raise event onResolve.raise(SocketResolveEventArgs(*this, !_errorCode ? (*_epIt).host_name() : String(""), _errorCode)); // perform connect, calling back to anonymous function if(!_errorCode) connect(*_epIt); }; // Resolve the host calling back to anonymous function Root::instance().resolveHost(_host, _port, anonResolve); }; // eo connect The message() function of the error_code is: The I/O operation has been aborted because of either a thread exit or an application request And my main.cpp looks like this: int _tmain(int argc, _TCHAR* argv[]) { morse::Root root; TextSocket s; s.connect("somehost.com", 1234); while(true) { root.performIO(); // calls io_service::run_one() } return 0; } Thanks in advance!

    Read the article

  • Boost Property_Tree iterators, how to handle them?

    - by Andry
    Hello... I am sorry but I asked a question about the same argument before, but my problem concerns another aspect of the one described in that question (How to iterate a boost...). My problem is this, take a look at the following code: #include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/algorithm/string/trim.hpp> int main(int argc, char** argv) { using boost::property_tree::ptree; ptree pt; read_xml("try.xml", pt); ptree::const_iterator end = pt.end(); for (ptree::const_iterator it = pt.begin(); it != end; it++) std::cout << "Here " << it->? << std::endl; } Well, as told me in the previous question, there is the possibility to use iterators on property_tree in Boost, but I do not know what type it is... and what methods or properties I can use... Well, I assume that it must be another ptree or something representing another xml hierarchy to be browsed again (if I want) but documentation about this is very bad... I do not know why, but in boost docs I cannot find nothing good about this... just something about a macro to browse nodes, but this approach is one I would really like to avoid... Well, the question is so... Once getting the iterator on a ptree, how can I access node name, value, parameters (a node in a xml file)? Thankyou

    Read the article

  • Boost threading/mutexs, why does this work?

    - by Flamewires
    Code: #include <iostream> #include "stdafx.h" #include <boost/thread.hpp> #include <boost/thread/mutex.hpp> using namespace std; boost::mutex mut; double results[10]; void doubler(int x) { //boost::mutex::scoped_lock lck(mut); results[x] = x*2; } int _tmain(int argc, _TCHAR* argv[]) { boost::thread_group thds; for (int x = 10; x>0; x--) { boost::thread *Thread = new boost::thread(&doubler, x); thds.add_thread(Thread); } thds.join_all(); for (int x = 0; x<10; x++) { cout << results[x] << endl; } return 0; } Output: 0 2 4 6 8 10 12 14 16 18 Press any key to continue . . . So...my question is why does this work(as far as i can tell, i ran it about 20 times), producing the above output, even with the locking commented out? I thought the general idea was: in each thread: calculate 2*x copy results to CPU register(s) store calculation in correct part of array copy results back to main(shared) memory I would think that under all but perfect conditions this would result in some part of the results array having 0 values. Is it only copying the required double of the array to a cpu register? Or is it just too short of a calculation to get preempted before it writes the result back to ram? Thanks.

    Read the article

  • Using boost::random to select from an std::list where elements are being removed

    - by user144182
    See this related question on more generic use of the Boost Random library. My questions involves selecting a random element from an std::list, doing some operation, which could potentally include removing the element from the list, and then choosing another random element, until some condition is satisfied. The boost code and for loop look roughly like this: // create and insert elements into list std::list<MyClass> myList; //[...] // select uniformly from list indices boost::uniform_int<> indices( 0, myList.size()-1 ); boost::variate_generator< boost::mt19937, boost::uniform_int<> > selectIndex(boost::mt19937(), indices); for( int i = 0; i <= maxOperations; ++i ) { int index = selectIndex(); MyClass & mc = myList.begin() + index; // do operations with mc, potentially removing it from myList //[...] } My problem is as soon as the operations that are performed on an element result in the removal of an element, the variate_generator has the potential to select an invalid index in the list. I don't think it makes sense to completely recreate the variate_generator each time, especially if I seed it with time(0).

    Read the article

  • php if clause inside foreach not retrieving data correctly

    - by Mike
    Here's my issue: In my controller, I want to grab user input from a form. I then parse the input, and compare it to database values to ensure I'm grabbing the correct input. I simply want to match the user's answers to the question, grab the user ID, the question ID, and then determine if the answer applies to a multiple choice or checkbox question, or something else. I take those values and insert them into the answer table. Ignore the waiver stuff. I'll test that once I get the answers input correctly. // add answers and waiver consent records try { $answerArray = array(); $waiverArray = array(); // retrieve answers, waiver consents, and the question ID's from form object foreach ($formData as $key => $value) { $parts = explode("_", $key); if ($parts[0] == 'question') { array_push($answerArray, $value); } if ($parts[0] == 'waiverTitle') { array_push($waiverArray, $value); } } $questions = new Model_DbTable_Questions(); $questionResults = $questions->getQuestionResults($session->idEvent); foreach ( $questionResults as $qr ) { if ($qr ['questionType'] == 'multipleChoice' || $qr ['questionType'] == 'checkBox') { foreach ( $answerArray as $aa ) { $answerData = $answers->addAnswer ( $lastUserID, $qr ['idQuestion'], null, $aa ); echo count ( $answerData ) . ', ' . $qr ['questionType'] . ', ' . $aa . '<br />'; } } else { foreach ( $answerArray as $aa ) { $answerData = $answers->addAnswer ( $lastUserID, $qr ['idQuestion'], $aa, null ); echo count ( $answerData ) . ', ' . $qr ['questionType'] . ', ' . $aa . '<br />'; } } } } catch (Zend_Db_Statement_Exception $e) { $e->getMessage(); throw $e; } From my test data, I expect to get 2 records that match the multiple choice and checkbox criteria, and 1 record for text in the ELSE clause like this: 3, checkbox, 1 3, multipleChoice, 1 3, text, question_2 What I get is a 3x3 Cartesian product, 3 question elements each with the 3 possible answers like this output from the echo statements: 4, checkBox, 1 4, checkBox, 1 4, checkBox, question_2 4, multipleChoice, 1 4, multipleChoice, 1 4, multipleChoice, question_2 4, text, 1 4, text, 1 4, text, question_2 I've tried placing the IF clause inside the inner foreach, but I get the same results. I've been staring at this problem for way too long and cannot see what I'm doing wrong. Your kind assistance would be greatly appreciated. Please let me know if my request requires more clarification.

    Read the article

  • zend_form display group inside foreach

    - by Mike
    I want to create a display group generated from foreach() clause output. I can't seem to get the syntax correct. Here's the business logic: for each category row find the associated fees output the category description as a label and the fees as radio buttons then create a display group with the fees as the group elements and the category description as the legend. I then have a style sheet format the elements on the page. and here's the code: foreach ($categoryData as $categoryRow) { $fees[$i] = new Zend_Form_Element_Radio("fees[$i]"); $fees[$i]->setDescription(strval($categoryRow['description'])); foreach ($feeData as $feeRow) { if ($feeRow['categories_idCategory'] == $categoryRow['idCategory']){ $fees[$i] ->addMultiOption($feeRow['idFees'] . '-' . $feeRow['categories_idCategory'], $feeRow['amount'] . '-' . $feeRow['name']); } } $fees[$i]->setRequired(TRUE); $this->addElements(array($fees[$i])); $this->addDisplayGroup($feeRow['name'], 'feeGroup',array('legend' => strval($feeRow['description']))); $i++; } I tried placing the addDisplayGroup() code within the foreach(), but I get the error: Message: No valid elements specified for display group So, my guess is that I'm making some kind of novice mistake that you experts will spot right away. I appreciate your time and attention to this matter.

    Read the article

  • Boost and XML (c++)

    - by Nuno
    Hi, Is there any good way (and a simple way too) using boost to read and write xml files? I can't seem to find any simple sample to read xml files using boost? (can you point me some simple sample that use boost for reading and writing xml files) If not boost, is out there any good and simple library to read and write xml files that you can recommend? (it must be a c++ library) Thanks Nuno

    Read the article

  • How Important is Boost to Learn for C++ Developers

    - by mahesh
    I am curious to learn Boost. But i wanted to ask how important it is to learn. What pre-requisite one should need before jumping on Boost. Why i am curious to know about Boost is that many people are talking about Boost on IRC's channels and here in StackOverflow. Thanks in advance.

    Read the article

  • How to remove compiler flag when building Boost

    - by mlo
    I need to build Boost with a non-standard set of flags (due to a conflict between Boost threading and C++/CLI). I'm adding the required flag (/clr) using CXXFLAGS, but this flag conflicts with the Boost default /EHs flag (/clr implies /EHa which is incompatible with /EHs), so that needs to be suppressed. Is there a mechanism like CXXFLAGS to suppress a default Boost flag or must I edit all of the compiler specification files by hand?

    Read the article

  • Signals and threads - good or bad design decision?

    - by Jens
    I have to write a program that performs highly computationally intensive calculations. The program might run for several days. The calculation can be separated easily in different threads without the need of shared data. I want a GUI or a web service that informs me of the current status. My current design uses BOOST::signals2 and BOOST::thread. It compiles and so far works as expected. If a thread finished one iteration and new data is available it calls a signal which is connected to a slot in the GUI class. My question(s): Is this combination of signals and threads a wise idea? I another forum somebody advised someone else not to "go down this road". Are there potential deadly pitfalls nearby that I failed to see? Is my expectation realistic that it will be "easy" to use my GUI class to provide a web interface or a QT, a VTK or a whatever window? Is there a more clever alternative (like other boost libs) that I overlooked? following code compiles with g++ -Wall -o main -lboost_thread-mt <filename>.cpp code follows: #include <boost/signals2.hpp> #include <boost/thread.hpp> #include <boost/bind.hpp> #include <iostream> #include <iterator> #include <string> using std::cout; using std::cerr; using std::string; /** * Called when a CalcThread finished a new bunch of data. */ boost::signals2::signal<void(string)> signal_new_data; /** * The whole data will be stored here. */ class DataCollector { typedef boost::mutex::scoped_lock scoped_lock; boost::mutex mutex; public: /** * Called by CalcThreads call the to store their data. */ void push(const string &s, const string &caller_name) { scoped_lock lock(mutex); _data.push_back(s); signal_new_data(caller_name); } /** * Output everything collected so far to std::out. */ void out() { typedef std::vector<string>::const_iterator iter; for (iter i = _data.begin(); i != _data.end(); ++i) cout << " " << *i << "\n"; } private: std::vector<string> _data; }; /** * Several of those can calculate stuff. * No data sharing needed. */ struct CalcThread { CalcThread(string name, DataCollector &datcol) : _name(name), _datcol(datcol) { } /** * Expensive algorithms will be implemented here. * @param num_results how many data sets are to be calculated by this thread. */ void operator()(int num_results) { for (int i = 1; i <= num_results; ++i) { std::stringstream s; s << "["; if (i == num_results) s << "LAST "; s << "DATA " << i << " from thread " << _name << "]"; _datcol.push(s.str(), _name); } } private: string _name; DataCollector &_datcol; }; /** * Maybe some VTK or QT or both will be used someday. */ class GuiClass { public: GuiClass(DataCollector &datcol) : _datcol(datcol) { } /** * If the GUI wants to present or at least count the data collected so far. * @param caller_name is the name of the thread whose data is new. */ void slot_data_changed(string caller_name) const { cout << "GuiClass knows: new data from " << caller_name << std::endl; } private: DataCollector & _datcol; }; int main() { DataCollector datcol; GuiClass mc(datcol); signal_new_data.connect(boost::bind(&GuiClass::slot_data_changed, &mc, _1)); CalcThread r1("A", datcol), r2("B", datcol), r3("C", datcol), r4("D", datcol), r5("E", datcol); boost::thread t1(r1, 3); boost::thread t2(r2, 1); boost::thread t3(r3, 2); boost::thread t4(r4, 2); boost::thread t5(r5, 3); t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); datcol.out(); cout << "\nDone" << std::endl; return 0; }

    Read the article

  • How to iterate over an array of objects without foreach and ArrayAccess

    - by kenny99
    Hi, I'm having to develop a site on PHP 5.1.6 and I've just come across a bug in my site which isn't happening on 5.2+. When using foreach() to iterate over an object, I get the following error: "Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference..." Does anyone know how to convert the following foreach loop to a construct which will work with 5.1.6? Thanks in advance! foreach ($post['commercial_brands'] as $brand) { $comm_food = new Commercial_food_Model; $comm_food->brand = $brand; $comm_food->feeding_type_id = $f_type->id; $comm_food->save(); }

    Read the article

  • Passing in a value to a usercontrol through a foreach loop

    - by LooDaFunk
    in my asp.net mark up I have a foreach loop that iterates through a simple list. In this foreach loop I am adding a new user control and attempting to pass in the value from the loop. However, this value just wont budge and get inside that damn control! Anyone have any suggestions? <%foreach (userInfo i in this.items) { %> <uc1:ItemControl ID="ItemControl" runat="server" UserID='<%#Eval("userID") %>'/> <%} %> userID is a public property in the control, when it goes to set, the value is just literally : <%#Eval("userID") %. I've tried #Bind and =Value but nothing seems to work. Any help would be appreciated!

    Read the article

  • h:graphicimage not working in c:foreach

    - by Muneeswaran Balasubramanian
    I have used c:forEach loop for display the list of images using h:graphicImage. But I can't display the images. I have the h:commandLink also in my page. The image have to be displayed at the time of form inititalization. But its not working. But after click the h:commandlink, the images are displayed properly. Before that it shows the image not found text (alt message). I have used h:graphicImage tag like below <c:forEach items="#{Sample.imageList}" var="images" varstatus="imageStatus"> <h:graphicimage id="image" url="#{images}" alt="Image Not Found"/> </c:forEach> What I do wrong in that and how can I achieve that?

    Read the article

  • Two foreach loops, ideea for my code please

    - by webmasters
    Please give me an ideea for my code, its a simple links script. TY I need two foreach loops, one which loops my sites and one which loops my anchors. So i'll have <li>link to site1 and anchor to site1</li> <li>link to site2 and anchor to site2</li> <li>link to site3 and anchor to site3</li> $currentsite = ''.bloginfo('wpurl').''; $mysites = array('http://site1.com', 'http://site2.com', 'http://site3.com'); $myanchors = array('anchor1','anchor2','anchor3'); foreach($mysites as $mysite) ****** i need a foreach loop for the anchors array ******* { if ( $mysite !== $currentsite ){echo '<li><a href="'.$mysite.'" title="'.$myanchor.'">'.$myanchor.'</a></li>';} }

    Read the article

  • How can I build the Boost.Python example on Ubuntu 9.10?

    - by Gatlin
    I am using Ubuntu 9.10 beta, whose repositories contain boost 1.38. I would like to build the hello-world example. I followed the instructions here (http://www.boost.org/doc/libs/1%5F40%5F0/libs/python/doc/tutorial/doc/html/python/hello.html), found the example project, and issued the "bjam" command. I have installed bjam and boost-build. I get the following output: Jamroot:18: in modules.load rule python-extension unknown in module Jamfile</usr/share/doc/libboost1.38-doc/examples/libs/python/example>. /usr/share/boost-build/build/project.jam:312: in load-jamfile /usr/share/boost-build/build/project.jam:68: in load /usr/share/boost-build/build/project.jam:170: in project.find /usr/share/boost-build/build-system.jam:248: in load /usr/share/boost-build/kernel/modules.jam:261: in import /usr/share/boost-build/kernel/bootstrap.jam:132: in boost-build /usr/share/doc/libboost1.38-doc/examples/libs/python/example/boost-build.jam:7: in module scope I do not know enough about Boost (this is an exploratory exercise for myself) to understand why the python-extension macro in the included Jamroot is not valid. I am running this example from the install directory, so I have not altered the Jamroot's use-project setting. As a side question, if I were to just willy-nilly start a project in an arbitrary directory, how would I write my jamroot?

    Read the article

  • Solving a difficult incomplete type error

    - by ChAoS
    I get an incomplete type error when trying to compile my code. I know that it is related to includes, but my project is large and it uses several templates so I can't find which type is actually incomplete. The error message doesn't help either: Compiling: ../../../addons/ofxTableGestures/src/Graphics/objects/CursorFeedback.cpp In file included from ../../../addons/ofxTableGestures/ext/boost/fusion/include/invoke_procedure.hpp:10, from ../../../addons/ofxTableGestures/src/oscGestures/tuioApp.hpp:46, from /home/thechaos/Projectes/of_preRelease_v0061_linux_FAT/addons/../apps/OF-TangibleFramework/ofxTableGestures/src/Graphics/objects/CursorFeedback.hpp:35, from /home/thechaos/Projectes/of_preRelease_v0061_linux_FAT/addons/../apps/OF-TangibleFramework/ofxTableGestures/src/Graphics/objects/CursorFeedback.cpp:31: ../../../addons/ofxTableGestures/ext/boost/fusion/functional/invocation/invoke_procedure.hpp: In function ‘void boost::fusion::invoke_procedure(Function, const Sequence&) [with Function = void (tuio::CanBasicFingers<Graphic>::*)(long int, float, float, float, float, float), Sequence = boost::fusion::joint_view<boost::fusion::joint_view<boost::fusion::iterator_range<boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0> >, const boost::fusion::single_view<tuio::CanBasicFingers<Graphic>*> >, boost::fusion::iterator_range<boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 6> > >]’: ../../../addons/ofxTableGestures/src/oscGestures/tuioApp.hpp:122: instantiated from ‘void tuio::AlternateCallback<C, M, E>::run(tuio::TEvent*) [with C = tuio::CanBasicFingers<Graphic>, M = void (tuio::CanBasicFingers<Graphic>::*)(long int, float, float, float, float, float), E = tuio::TeventBasicFingersMoveFinger]’ /home/thechaos/Projectes/of_preRelease_v0061_linux_FAT/addons/../apps/OF-TangibleFramework/ofxTableGestures/src/Graphics/objects/CursorFeedback.cpp:64: instantiated from here ../../../addons/ofxTableGestures/ext/boost/fusion/functional/invocation/invoke_procedure.hpp:88: error: incomplete type ‘boost::fusion::detail::invoke_procedure_impl<void (tuio::CanBasicFingers<Graphic>::*)(long int, float, float, float, float, float), const boost::fusion::joint_view<boost::fusion::joint_view<boost::fusion::iterator_range<boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0> >, const boost::fusion::single_view<tuio::CanBasicFingers<Graphic>*> >, boost::fusion::iterator_range<boost::fusion::vector_iterator<boost::fusion::vector6<long int, float, float, float, float, float>, 0>, boost::fusion::vector_iterator<const boost::fusion::vector6<long int, float, float, float, float, float>, 6> > >, 7, true, false>’ used in nested name specifier If I copy the conflictive code to a same file I can compile it. So I know that the code itself is OK, the problem is the way I instantiate it. How can I trace the origin of this error? Is there any way to get the trace of the c++ compiler and preprocessor to get more informative messages?

    Read the article

  • async_write/async_read problems while trying to implement question-answer logic

    - by Max
    Good day. I'm trying to implement a question - answer logic using boost::asio. On the Client I have: void Send_Message() { .... boost::asio::async_write(server_socket, boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Client::Handle_Write_Message, this, boost::asio::placeholders::error)); .... } void Handle_Write_Message(const boost::system::error_code& error) { .... std::cout << "Message was sent.\n"; .... boost::asio::async_read(server_socket_,boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Client::Handle_Read_Message, this, boost::asio::placeholders::error)); .... } void Handle_Read_Message(const boost::system::error_code& error) { .... std::cout << "I have a new message.\n"; .... } And on the Server i have the "same - logic" code: void Read_Message() { .... boost::asio::async_read(client_socket, boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Server::Handle_Read_Message, this, boost::asio::placeholders::error)); .... } void Handle_Read_Message(const boost::system::error_code& error) { .... std::cout << "I have a new message.\n"; .... boost::asio::async_write(client_socket_,boost::asio::buffer(&Message, sizeof(Message)), boost::bind(&Server::Handle_Write_Message, this, boost::asio::placeholders::error)); .... } void Handle_Write_Message(const boost::system::error_code& error) { .... std::cout << "Message was sent back.\n"; .... } Message it's just a structure. And the output on the Client is: Message was sent. Output on the Server is: I have a new message. And that's all. After this both programs are still working but nothing happens. I tried to implement code like: if (!error) { .... } else { // close sockets and etc. } But there are no errors in reading or writing. Both programs are just running normally, but doesn't interact with each other. This code is quite obvious but i can't understand why it's not working. Thanks in advance for any advice.

    Read the article

  • g++ linker error--typeinfo, but not vtable

    - by James
    I know the standard answer for a linker error about missing typeinfo usually also involves vtable and some virtual function that I forgot to actually define. I'm fairly certain that's not the situation this time. Here's the error: UI.o: In function boost::shared_ptr<Graphics::Widgets::WidgetSet>::shared_ptr<Graphics::Resource::GroupByState>(boost::shared_ptr<Graphics::Resource::GroupByState> const&, boost::detail::dynamic_cast_tag)': UI.cpp:(.text._ZN5boost10shared_ptrIN8Graphics7Widgets9WidgetSetEEC1INS1_8Resource12GroupByStateEEERKNS0_IT_EENS_6detail16dynamic_cast_tagE[boost::shared_ptr<Graphics::Widgets::WidgetSet>::shared_ptr<Graphics::Resource::GroupByState>(boost::shared_ptr<Graphics::Resource::GroupByState> const&, boost::detail::dynamic_cast_tag)]+0x30): undefined reference totypeinfo for Graphics::Widgets::WidgetSet' Running c++filt on the obnoxious mangled name shows that it actually is looking at .boost::shared_ptr::shared_ptr(boost::shared_ptr const&, boost::detail::dynamic_cast_tag) The inheritance hierarchy looks something like class AbstractGroup { typedef boost::shared_ptr<AbstractGroup> Ptr; ... }; class WidgetSet : public AbstractGroup { typedef boost::shared_ptr<WidgetSet> Ptr; ... }; class GroupByState : public AbstractGroup { ... }; Then there's this: class UI : public GroupByState { ... void LoadWidgets( GroupByState::Ptr resource ); }; Then the original implementation: void UI::LoadWidgets( GroupByState::Ptr resource ) { WidgetSet::Ptr tmp( boost::dynamic_pointer_cast< WidgetSet >(resource) ); if( tmp ) { ... } } Stupid error on my part (trying to cast to a sibling class with a shared parent), even if the error is kind of cryptic. Changing to this: void UI::LoadWidgets( AbstractGroup::Ptr resource ) { WidgetSet::Ptr tmp( boost::dynamic_pointer_cast< WidgetSet >(resource) ); if( tmp ) { ... } } (which I'm fairly sure is what I actually meant to be doing) left me with a very similar error: UI.o: In function boost::shared_ptr<Graphics::Widgets::WidgetSet>::shared_ptr<Graphics::_Drawer::Group>(boost::shared_ptr<Graphics::_Drawer::Group> const&, boost::detail::dynamic_cast_tag)': UI.cpp:(.text._ZN5boost10shared_ptrIN8Graphics7Widgets9WidgetSetEEC1INS1_7_Drawer5GroupEEERKNS0_IT_EENS_6detail16dynamic_cast_tagE[boost::shared_ptr<Graphics::Widgets::WidgetSet>::shared_ptr<Graphics::_Drawer::Group>(boost::shared_ptr<Graphics::_Drawer::Group> const&, boost::detail::dynamic_cast_tag)]+0x30): undefined reference totypeinfo for Graphics::Widgets::WidgetSet' collect2: ld returned 1 exit status dynamic_cast_tag is just an empty struct in boost/shared_ptr.hpp. It's just a guess that boost might have anything at all to do with the error. Passing in a WidgetSet::Ptr totally eliminates the need for a cast, and it builds fine (which is why I think there's more going on than the standard answer for this question). Obviously, I'm trimming away a lot of details that might be important. My next step is to cut it down to the smallest example that fails to build, but I figured I'd try the lazy way out and take a stab on here first. TIA!

    Read the article

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