Search Results

Search found 1726 results on 70 pages for 'boost'.

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

  • 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

  • What is wrong with this attempt of sending a break-signal?

    - by Jook
    I have quite a headache about this seemingly easy task: send a break signal to my device, like the wxTerm (or any similar Terminal application) does. This signal has to be 125ms long, according to my tests and the devices specification. It should result in a specific response, but what I get is a longer response than expected, and the transmitted date is false. e.g.: what it should respond 08 00 81 00 00 01 07 00 what it does respond 08 01 0A 0C 10 40 40 07 00 7F What really boggles me is, that after I have used wxTerm to look at my available com-ports (without connecting or sending anything), my code starts to work! I can send then as many breaks as I like, I get my response right from then on. I have to reset my PC in order to try it again. What the heck is going on here?! Here is my code for a reset through a break-signal: minicom_client(boost::asio::io_service& io_service, unsigned int baud, const string& device) : active_(true), io_service_(io_service), serialPort(io_service, device) { if (!serialPort.is_open()) { cerr << "Failed to open serial port\n"; return; } boost::asio::serial_port_base::flow_control FLOW( boost::asio::serial_port_base::flow_control::hardware ); boost::asio::serial_port_base::baud_rate baud_option(baud); serialPort.set_option(FLOW); serialPort.set_option(baud_option); read_start(); std::cout << SetCommBreak(serialPort.native_handle()) << std::endl; std::cout << GetLastError() << std::endl; boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time(); boost::this_thread::sleep(boost::posix_time::millisec(125)); boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time(); std::cout << ClearCommBreak(serialPort.native_handle()) << std::endl; std::cout << GetLastError() << std::endl; boost::posix_time::time_duration msdiff = mst2 - mst1; std::cout << msdiff.total_milliseconds() << std::endl; } Edit: It was only necessary to look at the combo-box selection of com-ports of wxTerm - no active connection was needed to be established in order to make my code work. I am guessing, that there is some sort of initialisation missing, which is done, when wxTerm is creating the list for the serial-port combo-box.

    Read the article

  • Boost.python building

    - by Ockonal
    Hi guys, really can't understand, how to build correctly project that uses boost.python. I've included boost_(python/thread/system)-mt. Here is simple module file: #include <boost/python.hpp> #include "script.hpp" #include "boost/python/detail/wrap_python.hpp" BOOST_PYTHON_MODULE(temp) { namespace py = boost::python; py::def("PyLog", &engine::log); } Here is bulid log: http://dpaste.com/179232/. Can't imagine what I forgot. System: arch linux; ls /usr/lib |grep boost : http://dpaste.com/179233/

    Read the article

  • Zlib compression in boost::iostreams not compatible with zlib.NET

    - by Johan
    Hello, I want to send compressed data between my C# to a C++ application in ZLIB format. In C++, I use the zlib_compressor/zlib_decompressor available in boost::iostreams. In C#, I am currently using the ZOutputStream available in the zlib.NET library. First of all, when I compress the same data using both libraries, the results look different: boost::iostreams::zlib_compressor: FF 13 49 48 00 00 01 00 01 00 00 00 63 61 60 60 F8 00 C4 C1 25 45 99 79 E9 23 87 04 00 zlib.NET (zlib.ZOutputStream): FF 13 49 48 00 00 01 00 01 00 00 00 78 9C 63 61 60 60 F8 00 C4 C1 25 45 99 79 E9 23 87 04 00 4F 31 63 8D (Note the 78 9C pattern that is present in zlib.NET, but not in boost). Furthermore, when I decompress data in boost that I compressed in zlib.NET, I am not able to read from the stream suggesting something is wrong. It does work when I try to decompress data compressed in boost. Does anybody know what is going wrong? Thank you, Johan

    Read the article

  • Using boost::iostreams to parse a binary file byte by byte

    - by Zsol
    So I would like to parse a binary file and extract some data from it. The problem I am facing with this is that I need to convert a stream of chars to a stream of unsigned chars. Reading the boost documentation, it seems that boost::iostreams::code_converter should be the solution for this, so I tried this: typedef unsigned char uint8_t; typedef boost::iostreams::stream<boost::iostreams::code_converter< boost::iostreams::basic_array_source<uint8_t> >, std::codecvt<uint8_t, char, std::mbstate_t> > array_stream; The idea was to specify a codecvt with InternalType=uint8_t and ExternalType=char. Unfortunately this does not compile. So the question is: how do I convert a stream of chars to a stream of uint8_ts?

    Read the article

  • Building Boost with LSB C++ Compiler

    - by Alex Farber
    I want to build my program with LSB C++ Compiler from the Linux Standard Base http://www.linuxfoundation.org/collaborate/workgroups/lsb. Program depends on the Boost library, built with gcc 4.4 version. Compilation fails. Is it possible to build the Boost library with LSB C++ Compiler? Alternatively, is it possible to build the Boost library with some old gcc version, what version is recommended? My final goal is to get my executable and third-party Boost libraries running on most Linux distributions. Generally, what can be done to get better binary compatibility for Linux distributions, developing C++ closed-source application depending on the Boost library?

    Read the article

  • Python extension building with boost

    - by user1544053
    Hey guys I'm fairly new to boost c/c++ library. I downloaded boost library and build the library. I created a very simple python library in c++ using boost interface (actually it is example code given in the documentation). I built it into a dll file. In the documentation it reads that this dll is exposed to python and they just show the import function in python and include the created library. I don't understand how to expose that dll to python and load the library inside in tradition ('import') manner. In case if you wanna look at the code then here it is: #include <boost/python.hpp> char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } Please help I really want to build applications with c/c++ and python. I simply want to use hello_ext as: >>>import hello_ext >>>print hello_ext.greet() Thank you.

    Read the article

  • boost::this_thread::disable_interruption usage confusion

    - by Evgenii
    boost/thread/pthread/shared_mutex.hpp contains this code: ... #include <boost/thread/detail/thread_interruption.hpp> ... class shared_mutex { ... void lock_shared() { boost::this_thread::disable_interruption do_not_disturb; boost::mutex::scoped_lock lk(state_change); while(state.exclusive || state.exclusive_waiting_blocked) { shared_cond.wait(lk); } ++state.shared_count; } ... }; but boost/thread/detail/thread_interruption.hpp does not contain implementation of disable_interruption, only the prototype. in boost_1_42_0/libs/thread/src/pthread we don't have the implementation too how does it work!???

    Read the article

  • Boost ASIO read X bytes synchroniously into a vector

    - by xeross
    Hey, I've been attempting to write a client/server app with boost now, so far it sends and receives but I can't seem to just read X bytes into a vector. If I use the following code vector<uint8_t> buf; for (;;) { buf.resize(4); boost::system::error_code error; size_t len = socket.read_some(boost::asio::buffer(buf), error); if (error == boost::asio::error::eof) break; // Connection closed cleanly by peer. else if (error) throw boost::system::system_error(error); // Some other error. } And the packet is bigger then 4 bytes then it seems it keeps writing into those 4 bytes until the entire packet has been received, however I want it to fetch 4 bytes, then allow me to parse them, and then get the rest of the packet. Can anyone provide me with a working example, or at least a pointer on how to make it work properly ? Regards, Xeross

    Read the article

  • How do I get the size of the boost buffer

    - by Anonymous
    I am trying to make an asynchronised server in visual studio and I use boost::asio::async_read(m_socket, boost::asio::buffer(m_buffer), boost::bind(&tcp_connection::handle_read, shared_from_this(), boost::asio::placeholders::error)); to get the buffer to be put in m_buffer boost::array<char, 256> m_buffer; but how do I get the size of this thing, m_buffer? size() didn't work, end() didn't work.. Any help would be fantastic. Thanks in advance.

    Read the article

  • how to use replace_regex_copy() from boost::algorithm library?

    - by Vincenzo
    This is my code: #include <string> #include <boost/algorithm/string/regex.hpp> string f(const string& s) { using namespace boost::algorithm; return replace_regex_copy(s, "\\w", "?"); } This is what compiler says: no matching function for call to ‘replace_regex_copy(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::string, std::string) The link to the library: http://www.boost.org/doc/libs/1_43_0/doc/html/boost/algorithm/replace_regex_copy.html Could anyone please help? Thanks! ps. Boost library is in place, since other functions from it work fine.

    Read the article

  • Using * Width & Precision Specifiers With boost::format

    - by John Dibling
    I am trying to use width and precision specifiers with boost::format, like this: #include <boost\format.hpp> #include <string> int main() { int n = 5; std::string s = (boost::format("%*.*s") % (n*2) % (n*2) % "Hello").str(); return 0; } But this doesn't work because boost::format doesn't support the * specifier. Boost throws an exception when parsing the string. Is there a way to accomplish the same goal, preferably using a drop-in replacement?

    Read the article

  • boost::filesystem - how to create a boost path from a windows path string on posix plattforms?

    - by VolkA
    I'm reading path names from a database which are stored as relative paths in Windows format, and try to create a boost::filesystem::path from them on a Unix system. What happens is that the constructor call interprets the whole string as the filename. I need the path to be converted to a correct Posix path as it will be used locally. I didn't find any conversion functions in the boost::filesystem reference, nor through google. Am I just blind, is there an obvious solution? If not, how would you do this? Example: std::string win_path("foo\\bar\\asdf.xml"); std::string posix_path("foo/bar/asdf.xml"); // loops just once, as part is the whole win_path interpreted as a filename boost::filesystem::path boost_path(win_path); BOOST_FOREACH(boost::filesystem::path part, boost_path) { std::cout << part << std::endl; } // prints each path component separately boost::filesystem::path boost_path_posix(posix_path); BOOST_FOREACH(boost::filesystem::path part, boost_path_posix) { std::cout << part << std::endl; }

    Read the article

  • wrapping boost::ublas with swig

    - by leon
    I am trying to pass data around the numpy and boost::ublas layers. I have written an ultra thin wrapper because swig cannot parse ublas' header correctly. The code is shown below #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/matrix.hpp> #include <boost/lexical_cast.hpp> #include <algorithm> #include <sstream> #include <string> using std::copy; using namespace boost; typedef boost::numeric::ublas::matrix<double> dm; typedef boost::numeric::ublas::vector<double> dv; class dvector : public dv{ public: dvector(const int rhs):dv(rhs){;}; dvector(); dvector(const int size, double* ptr):dv(size){ copy(ptr, ptr+sizeof(double)*size, &(dv::data()[0])); } ~dvector(){} }; with the SWIG interface that looks something like %apply(int DIM1, double* INPLACE_ARRAY1) {(const int size, double* ptr)} class dvector{ public: dvector(const int rhs); dvector(); dvector(const int size, double* ptr); %newobject toString; char* toString(); ~dvector(); }; I have compiled them successfully via gcc 4.3 and vc++9.0. However when I simply run a = dvector(array([1.,2.,3.])) it gives me a segfault. This is the first time I use swigh with numpy and not have fully understanding between the data conversion and memory buffer passing. Does anyone see something obvious I have missed? I have tried to trace through with a debugger but it crashed within the assmeblys of python.exe. I have no clue if this is a swig problem or of my simple wrapper. Anything is appreciated.

    Read the article

  • Boost thread synchronization in release build

    - by Joseph16
    Hi, when I try to run the following code in debug and release mode in VS2005. Each time I see different output in console and It doesn't seem like the multithreading is achieved in release mode. 1. #include <boost/thread.hpp> 2. #include <iostream> 3. 4. void wait(int seconds) 5. { 6. boost::this_thread::sleep(boost::posix_time::seconds(seconds)); 7. } 8. 9. boost::mutex mutex; 10. 11. void thread() 12. { 13. for (int i = 0; i < 5; ++i) 14. { 15. //wait(1); 16. mutex.lock(); 17. std::cout << "Thread " << boost::this_thread::get_id() << ": " << i << std::endl; 18. mutex.unlock(); 19. } 20. } 21. 22. int main() 23. { 24. boost::thread t1(thread); 25. boost::thread t2(thread); 26. t1.join(); 27. t2.join(); 28. } Debug Mode Thread 00153E60: 0 Thread 00153E90: 0 Thread 00153E60: 1 Thread 00153E90: 1 Thread 00153E90: 2 Thread 00153E60: 2 Thread 00153E90: 3 Thread 00153E60: 3 Thread 00153E60: 4 Thread 00153E90: 4 Press any key to continue . . . Release Mode Thread 00153D28: 0 Thread 00153D28: 1 Thread 00153D28: 2 Thread 00153D28: 3 Thread 00153D28: 4 Thread 00153D58: 0 Thread 00153D58: 1 Thread 00153D58: 2 Thread 00153D58: 3 Thread 00153D58: 4 Press any key to continue . . .

    Read the article

  • Why boost property tree write_json saves everything as string? Is it possible to change that?

    - by pprzemek
    I'm trying to serialize using boost property tree write_json, it saves everything as strings, it's not that data are wrong, but I need to cast them explicitly every time and I want to use them somewhere else. (like in python or other C++ json (non boost) library) here is some sample code and what I get depending on locale: boost::property_tree::ptree root, arr, elem1, elem2; elem1.put<int>("key0", 0); elem1.put<bool>("key1", true); elem2.put<float>("key2", 2.2f); elem2.put<double>("key3", 3.3); arr.push_back( std::make_pair("", elem1) ); arr.push_back( std::make_pair("", elem2) ); root.put_child("path1.path2", arr); std::stringstream ss; write_json(ss, root); std::string my_string_to_send_somewhare_else = ss.str(); and my_string_to_send_somewhere_else is sth. like this: { "path1" : { "path2" : [ { "key0" : "0", "key1" : "true" }, { "key2" : "2.2", "key3" : "3.3" } ] } } Is there anyway to save them as the values, like: "key1" : true or "key2" : 2.2 ?

    Read the article

  • Intel turbo boost - in reality

    - by gisek
    I have an Intel i7-3630QM processor in my laptop. Its speed is supposed to be from 2.4 to 3.4 GHz in turbo boost mode. In reality, will it ever run all cores on full speed (3.4GHz mentioned above) at the same time? I heard somewhere that this additional 1GHz is shared between all cores in laptops. If the boost is 1GHz per core it's pretty impressive (over 40% speed up). What does it really look like? How long can a processor run in turbo mode?

    Read the article

  • Re: Help with Boost Grammar

    - by Decmac04
    I have redesigned and extended the grammar I asked about earlier as shown 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 include include include include include //////////////////////////////////////////////////////////////////////////// using namespace std; using namespace boost::spirit; //////////////////////////////////////////////////////////////////////////// // // Semantic Actions // //////////////////////////////////////////////////////////////////////////// // // namespace { //semantic action function on individual lexeme void do_noint(char const* start, char const* end) { string str(start, end); if (str != "NAT1") cout << "PUSH(" << str << ')' << endl; } //semantic action function on addition of lexemes void do_add(char const*, char const*) { cout << "ADD" << endl; // for(vector::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; } //semantic action function on multiplication of lexemes void do_mult(char const*, char const*) { cout << "\nMULTIPLY" << endl; } //semantic action function on division of lexemes void do_div(char const*, char const*) { cout << "\nDIVIDE" << endl; } // // vector flowTable; //semantic action function on simple substitution void do_sSubst(char const* start, char const* end) { string str(start, end); //use boost tokenizer to break down tokens typedef boost::tokenizer Tokenizer; boost::char_separator sep(" -+/*:=()",0,boost::drop_empty_tokens); // char separator definition Tokenizer tok(str, sep); Tokenizer::iterator tok_iter = tok.begin(); pair dependency; //create a pair object for dependencies //create a vector object to store all tokens vector dx; // int counter = 0; // tracks token position for(tok.begin(); tok_iter != tok.end(); ++tok_iter) //save all tokens in vector { dx.push_back(*tok_iter ); } counter = dx.size(); // vector d_hat; //stores set of dependency pairs string dep; //pairs variables as string object // dependency.first = *tok.begin(); vector FV; for(int unsigned i=1; i < dx.size(); i++) { // if(!atoi(dx.at(i).c_str()) && (dx.at(i) !=" ")) { dependency.second = dx.at(i); dep = dependency.first + "|-" + dependency.second + " "; d_hat.push_back(dep); vector<string> row; row.push_back(dependency.first); //push x_hat into first column of each row for(unsigned int j=0; j<2; j++) { row.push_back(dependency.second);//push an element (column) into the row } flowTable.push_back(row); //Add the row to the main vector } } //displays internal representation of information flow table cout << "\n****************\nDependency Table\n****************\n"; cout << "X_Hat\tDx\tG_Hat\n"; cout << "-----------------------------\n"; for(unsigned int i=0; i < flowTable.size(); i++) { for(unsigned int j=0; j<2; j++) { cout << flowTable[i][j] << "\t "; } if (*tok.begin() != "WHILE" ) //if there are no global flows, cout << "\t{}"; //display empty set cout << "\n"; } cout << "***************\n\n"; for(int unsigned j=0; j < FV.size(); j++) { if(FV.at(j) != dependency.second) dep = dependency.first + "|-" + dependency.second + " "; d_hat.push_back(dep); } cout << "PUSH(" << str << ')' << endl; cout << "\n*******\nDependency pairs\n*******\n"; for(int unsigned i=0; i < d_hat.size(); i++) cout << d_hat.at(i) << "\n...\n"; cout << "\nSIMPLE SUBSTITUTION\n\n"; } //semantic action function on multiple substitution void do_mSubst(char const* start, char const* end) { string str(start, end); cout << "PUSH(" << str << ')' << endl; //cout << "\nMULTIPLE SUBSTITUTION\n\n"; } //semantic action function on unbounded choice substitution void do_mChoice(char const* start, char const* end) { string str(start, end); cout << "PUSH(" << str << ')' << endl; cout << "\nUNBOUNDED CHOICE SUBSTITUTION\n\n"; } void do_logicExpr(char const* start, char const* end) { string str(start, end); //use boost tokenizer to break down tokens typedef boost::tokenizer Tokenizer; boost::char_separator sep(" -+/*=:()<",0,boost::drop_empty_tokens); // char separator definition Tokenizer tok(str, sep); Tokenizer::iterator tok_iter = tok.begin(); //pair dependency; //create a pair object for dependencies //create a vector object to store all tokens vector dx; for(tok.begin(); tok_iter != tok.end(); ++tok_iter) //save all tokens in vector { dx.push_back(*tok_iter ); } for(unsigned int i=0; i cout << "PUSH(" << str << ')' << endl; cout << "\nPREDICATE\n\n"; } void do_predicate(char const* start, char const* end) { string str(start, end); cout << "PUSH(" << str << ')' << endl; cout << "\nMULTIPLE PREDICATE\n\n"; } void do_ifSelectPre(char const* start, char const* end) { string str(start, end); //if cout << "PUSH(" << str << ')' << endl; cout << "\nPROTECTED SUBSTITUTION\n\n"; } //semantic action function on machine substitution void do_machSubst(char const* start, char const* end) { string str(start, end); cout << "PUSH(" << str << ')' << endl; cout << "\nMACHINE SUBSTITUTION\n\n"; } } //////////////////////////////////////////////////////////////////////////// // // Machine Substitution Grammar // //////////////////////////////////////////////////////////////////////////// // Simple substitution grammar parser with integer values removed struct Substitution : public grammar { template struct definition { definition(Substitution const& ) { machine_subst = ( (simple_subst) | (multi_subst) | (if_select_pre_subst) | (unbounded_choice) )[&do_machSubst] ; unbounded_choice = str_p("ANY") ide_list str_p("WHERE") predicate str_p("THEN") machine_subst str_p("END") ; if_select_pre_subst = ( ( str_p("IF") predicate str_p("THEN") machine_subst *( str_p("ELSIF") predicate machine_subst ) !( str_p("ELSE") machine_subst) str_p("END") ) | ( str_p("SELECT") predicate str_p("THEN") machine_subst *( str_p("WHEN") predicate machine_subst ) !( str_p("ELSE") machine_subst) str_p("END")) | ( str_p("PRE") predicate str_p("THEN") machine_subst str_p("END") ) )[&do_ifSelectPre] ; multi_subst = ( (machine_subst) *( ( str_p("||") (machine_subst) ) | ( str_p("[]") (machine_subst) ) ) ) [&do_mSubst] ; simple_subst = (identifier str_p(":=") arith_expr) [&do_sSubst] ; expression = predicate | arith_expr ; predicate = ( (logic_expr) *( ( ch_p('&') (logic_expr) ) | ( str_p("OR") (logic_expr) ) ) )[&do_predicate] ; logic_expr = ( identifier (str_p("<") arith_expr) | (str_p("<") arith_expr) | (str_p("/:") arith_expr) | (str_p("<:") arith_expr) | (str_p("/<:") arith_expr) | (str_p("<<:") arith_expr) | (str_p("/<<:") arith_expr) | (str_p("<=") arith_expr) | (str_p("=") arith_expr) | (str_p("=") arith_expr) | (str_p("=") arith_expr) ) [&do_logicExpr] ; arith_expr = term *( ('+' term)[&do_add] | ('-' term)[&do_subt] ) ; term = factor ( ('' factor)[&do_mult] | ('/' factor)[&do_div] ) ; factor = lexeme_d[( identifier | +digit_p)[&do_noint]] | '(' expression ')' | ('+' factor) ; ide_list = identifier *( ch_p(',') identifier ) ; identifier = alpha_p +( alnum_p | ch_p('_') ) ; } rule machine_subst, unbounded_choice, if_select_pre_subst, multi_subst, simple_subst, expression, predicate, logic_expr, arith_expr, term, factor, ide_list, identifier; rule<ScannerT> const& start() const { return predicate; //return multi_subst; //return machine_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"; string str; int machineCount = 0; char strFilename[256]; //file name store as a string object do { cout << "Please enter a filename...or [q or Q] to quit:\n\n "; //prompt for file name to be input //char strFilename[256]; //file name store as a string object cin strFilename; if(*strFilename == 'q' || *strFilename == 'Q') //termination condition return 0; ifstream inFile(strFilename); // opens file object for reading //output file for truncated machine (operations only) if (inFile.fail()) cerr << "\nUnable to open file for reading.\n" << endl; inFile.unsetf(std::ios::skipws); Substitution elementary_subst; // Simple substitution parser object string next; while (inFile str) { getline(inFile, next); str += next; if (str.empty() || str[0] == 'q' || str[0] == 'Q') break; parse_info< info = parse(str.c_str(), elementary_subst !end_p, 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"; } } } while ( (*strFilename != 'q' || *strFilename !='Q')); return 0; } However, I am experiencing the following unexpected behaviours on testing: The text files I used are: f1.txt, ... containing ...: debt:=(LoanRequest+outstandingLoan1)*20 . f2.txt, ... containing ...: debt:=(LoanRequest+outstandingLoan1)*20 || newDebt := loanammount-paidammount || price := purchasePrice + overhead + bb . f3.txt, ... containing ...: yy < (xx+7+ww) . f4.txt, ... containing ...: yy < (xx+7+ww) & yy : NAT . When I use multi_subst as start rule both files (f1 and f2) are parsed correctly; When I use machine_subst as start rule file f1 parse correctly, while file f2 fails, producing the error: “Parsing failed stopped at: || newDebt := loanammount-paidammount || price := purchasePrice + overhead + bb” When I use predicate as start symbol, file f3 parse correctly, but file f4 yields the error: “ “Parsing failed stopped at: & yy : NAT” Can anyone help with the grammar, please? It appears there are problems with the grammar that I have so far been unable to spot.

    Read the article

  • What header file is where the boost libray define its own primitive data type?

    - by ronghai
    Recently, I try to use the boost::spirit::qi binary endian parser to parse some binary data depends on the endianness of the Platform. There is a simple example, like following: Using declarations and variables: using boost::spirit::qi::little_word; using boost::spirit::qi::little_dword; using boost::spirit::qi::little_qword; boost::uint16_t us; boost::uint32_t ui; boost::uint64_t ul; Basic usage of the little endian binary parsers: test_parser_attr("\x01\x02", little_word, us); assert(us == 0x0201); test_parser_attr("\x01\x02\x03\x04", little_dword, ui); assert(ui == 0x04030201); test_parser_attr("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword, ul); assert(ul == 0x0807060504030201LL); test_parser("\x01\x02", little_word(0x0201)); test_parser("\x01\x02\x03\x04", little_dword(0x04030201)); test_parser("\x01\x02\x03\x04\x05\x06\x07\x08", little_qword(0x0807060504030201LL)); It works very well. But my questions come, why do we need use some data types like boost::uint16_t, boost::uint32_t here? Can I use unsigned long or unsigned int here? And if I want to parse double or float data type, what boost data type should I use? And please tell me where is boost define the above these types? Thanks a lot.

    Read the article

  • How to convert a function that returns a int to a function that returns a bool using boost::bind?

    - by user814628
    I have something like the following: struct A{ virtual int derp(){ if(herp()) return 1; else return 0; } void slurp(){ boost::function<bool(int x, int y> purp = /** boost bind derp to match lvalue sig **/; } } Any ideas? I want to create the function prup which basically calls derp and ignores the (x,y) passed in. I need something like bool purp(int x, int y){ return derp(); } but want to avoid creating it as a member function, and rather just create it locally if possible?

    Read the article

  • boost.test and eclipse

    - by Anton Potapov
    Hi all, I'm using Eclipse CDT and Boost.Test(with Boost.Build). I would like Eclipse to parse output of Boost.Test generated during by run of test suites during build. Does anybody know how to achieve this? Thanks in advance

    Read the article

  • [C++] Write connected components of a graph using Boost Graph

    - by conradlee
    I have an file that is a long list of weighted edges, in the following form node1_id node2_id weight node1_id node3_id weight and so on. So one weighted edge per line. I want to load this file into boost graph and find the connected components in the graph. Each of these connected components is a subgraph. For each of these component subgraphs, I want to write the edges in the above-described format. I want to do all this using boost graph. This problem is in principle simple, it's just I'm not sure how to implement it neatly because I don't know my way around Boost Graph. I have already spent some hours and have code that will find the connected components, but my version is surely much longer and more complicated that necessary---I'm hoping there's a boost-graph ninja out there that can show me the right, easy way.

    Read the article

  • Mocking using boost::shared_ptr and AMOP

    - by Edison Gustavo Muenz
    Hi, I'm trying to write mocks using amop. I'm using Visual Studio 2008. I have this interface class: struct Interface { virtual void Activate() = 0; }; and this other class which receives pointers to this Interface, like this: struct UserOfInterface { void execute(Interface* iface) { iface->Activate(); } }; So I try to write some testing code like this: amop::TMockObject<Interface> mock; mock.Method(&Interface::Activate).Count(1); UserOfInterface user; user.execute((Interface*)mock); mock.Verifiy(); It works! So far so good, but what I really want is a boost::shared_ptr in the execute() method, so I write this: struct UserOfInterface { void execute(boost::shared_ptr<Interface> iface) { iface->Activate(); } }; How should the test code be now? I tried some things, like: amop::TMockObject<Interface> mock; mock.Method(&Interface::Activate).Count(1); UserOfInterface user; boost::shared_ptr<Interface> mockAsPtr((Interface*)mock); user.execute(mockAsPtr); mock.Verifiy(); It compiles, but obviously crashes, since at the end of the scope the variable 'mock' gets double destroyed (because of the stack variable 'mock' and the shared_ptr). I also tried to create the 'mock' variable on the heap: amop::TMockObject<Interface>* mock(new amop::TMockObject<Interface>); mock->Method(&Interface::Activate).Count(1); UserOfInterface user; boost::shared_ptr<Interface> mockAsPtr((Interface*)*mock); user.execute(mockAsPtr); mock->Verifiy(); But it doesn't work, somehow it enters an infinite loop, before I had a problem with boost not finding the destructor for the mocked object when the shared_ptr tried to delete the object. Has anyone used amop with boost::shared_ptr successfully?

    Read the article

  • Eclipse c++ with mingw comiler cant build boost regex example, can find .a library files

    - by Kim
    Hi, I'm trying to build the boost regex example in eclipse using mingw on vista. I built boost ok with mingw as there are library files XXXX.a. I could build/compile the first boost example that doesnt require any of the compiled boost libraries. When I compile the regex example I get a linker error saying it cant find the library file. I have tried various libray file names eg leave off the .a extension, leave off the lib prefix etc. Now the interesting thing is that if I leave off the library extension and rename the library file to XXX.lib it works and runs ok. So why cant it read the .a library file? It must be my setup somewhere but I dont know where or what to set. From what I read everyone is ok linking the .a file except me :( Thanks in advance, Kim

    Read the article

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