I'm capturing data in a boost::circular_buffer and would like to now perform a regex search on the contents but I'm having some difficulty getting boost::regex to understand how to look at the buffer.
Here's a stripped down version of the sort of thing I'd like to do based on the example here:
// Set up a pre-populated data buffer as an example
std::string test = "Fli<usefuldata>bble";
boost::circular_buffer<char> dataBuff;
for (std::string::iterator it = test.begin(); it != test.end(); ++it)
{
dataBuff.push_back(*it);
}
// Set up the regex
static const boost::regex e("<\\w*>");
std::string::const_iterator start, end;
start = dataBuff.begin(); // <-- error C2679
end = dataBuff.end();
boost::match_flag_type flags = boost::match_default;
// Try and find something of interest in the buffer
boost::match_results<std::string::const_iterator> what;
if (regex_search(start, end, what, e, flags))
{
// Do something - we found what we're after...
}
I (quite understandably I think) get this error when I try to compile:
1>c:\projects\ProtocolBufferProcessor\ProtocolBufferProcessor.h(53): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'boost::cb_details::iterator<Buff,Traits>' (or there is no acceptable conversion)
1> with
1> [
1> Buff=boost::circular_buffer<char>,
1> Traits=boost::cb_details::nonconst_traits<std::allocator<char>>
1> ]
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xstring(435): could be 'std::_String_iterator<_Elem,_Traits,_Alloc> &std::_String_iterator<_Elem,_Traits,_Alloc>::operator =(const std::_String_iterator<_Elem,_Traits,_Alloc> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> while trying to match the argument list '(std::_String_iterator<_Elem,_Traits,_Alloc>, boost::cb_details::iterator<Buff,Traits>)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> and
1> [
1> Buff=boost::circular_buffer<char>,
1> Traits=boost::cb_details::nonconst_traits<std::allocator<char>>
1> ]
...but is there anything I can do other than create a std::string character by character from the circular buffer each time I run the regex?
I'm using Boost v1.54 if that makes a difference.
you need to use the buffer's iterator type:
Live On Coliru
#include <boost/circular_buffer.hpp>
#include <boost/regex.hpp>
using buffer_t = boost::circular_buffer<char>;
int main() {
// Set up a pre-populated data buffer as an example
std::string test = "Fli<usefuldata>bble";
buffer_t dataBuff;
for (std::string::iterator it = test.begin(); it != test.end(); ++it)
{
dataBuff.push_back(*it);
}
// Set up the regex
static const boost::regex e("<\\w*>");
buffer_t::const_iterator start = dataBuff.begin(); // <-- error C2679
buffer_t::const_iterator end = dataBuff.end();
boost::match_flag_type flags = boost::match_default;
// Try and find something of interest in the buffer
boost::match_results<buffer_t::const_iterator> what;
if (regex_search(start, end, what, e, flags))
{
// Do something - we found what we're after...
}
}
I can not make a call to a method of a class from another class :rewrite the code cocos2d (objective-c) on cocos2d-x (c++)
Error:
c:\program files\microsoft visual studio 11.0\vc\include\xrefwrap(273): error C2562: std::_Pmd_caller<_Ret,_Arg0>::_Call_pmd: функция типа "void", возвращающая значение
1> with
1> [
1> _Ret=void,
1> _Arg0=cocos2d::Object
1> ]
1> c:\program files\microsoft visual studio 11.0\vc\include\xrefwrap(271): см. объявление "std::_Pmd_caller<_Ret,_Arg0>::_Call_pmd"
1> with
1> [
1> _Ret=void,
1> _Arg0=cocos2d::Object
1> ]
Not become fully kidat.Tam 20 more lines of the same
HudLayer.cpp
CCMenuItem *button = CCMenuItemImage::create("1.png","1.png",menu_selector(HelloWorld::createSprite));
HelloWorld.cpp
void HelloWorld::createSprite(CCObject *sender)
{
_sprite->initWithFile("bird.png");
_sprite->setPosition(ccp(x,y));
}
In the IronMan.h you have to declare
static void playClicked();
In the Avenger.cpp you can use this method
CCSize *screenSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint pointOrigin = CCDirector::sharedDirector()->getVisibleOrigin();
float x = screenSize.width;
float y = screenSize.height;*
CCWidgetLayout* widgetLayout = CCWidgetLayout::create();
addChild(widgetLayout);
CCButton* playButton = CCButton::create("btn1.png", "btn2.png", "btn3.png");
playButton->setPosition(x/1.2f,y/1.5f);
playButton->setClickSelector(this,click_selector(IronMan::playClicked));
widgetLayout->addChild(playButton,1);
You should do like this..
CCMenuItem *button = CCMenuItemImage::create("1.png","1.png",menu_selector(HudLayer::createSpriteMethod));
void HudLayer::createSpriteMethod(CCObject *sender)
{
_helloWorld//assuming you have instance of HelloWorld
_helloWorld->createSprite(sender);
}
for HelloWorld::createSprite.....it should be static method.,nothing good comes from it.
The boost examples for usage of the boost::graph library usually employ a graph like
using namespace boost;
typedef adjacency_list
< vecS, // edge container
vecS, // vertex container
undirectedS,
property<vertex_index_t, int>,
property<edge_index_t, int>
> graph;
and therefore they work very well.
But I have a graph with
typedef adjacency_list
< setS, // edge container
listS, // vertex container
undirectedS,
boost::no_property, // vertex property
boost::no_property // edge property
> graph;
and the algorithms don't work out of the box. In most cases a map for looking up a vertex_descriptor for a particular vertex index (integer value) has to be provided.
I want to check whether my graph is planar and compute a planar embedding of it.
I provide a vertex index map and it does work in that way for e.g. the connected_components algorithm, but obviously not for the boyer_myrvold_planarity_test:
using namespace boost;
typedef adjacency_list
<boost::setS, boost::listS, undirectedS,
boost::no_property, boost::no_property> graph;
typedef boost::graph_traits<graph>::edge_descriptor EdgeDesc;
typedef boost::graph_traits<graph>::vertex_descriptor VertexDesc;
typedef std::map<VertexDesc, size_t> VertexDescMap;
typedef std::map<EdgeDesc, size_t> EdgeDescMap;
typedef boost::graph_traits<graph>::vertex_iterator VertexIterator;
graph K_4;
std::vector<VertexDesc> vertex;
for(int i=0;i < 4; ++i){
VertexDesc v = boost::add_vertex(K_4);
vertex.push_back(v);
}
add_edge(vertex[0], vertex[1], K_4);
add_edge(vertex[0], vertex[2], K_4);
add_edge(vertex[0], vertex[3], K_4);
add_edge(vertex[1], vertex[2], K_4);
add_edge(vertex[1], vertex[3], K_4);
add_edge(vertex[2], vertex[3], K_4);
VertexDescMap vidxMap;
boost::associative_property_map<VertexDescMap> vindexMap(vidxMap);
VertexIterator di, dj;
boost::tie(di, dj) = boost::vertices(K_4);
for(int i = 0; di != dj; ++di,++i){
boost::put(vindexMap, (*di), i);
}
if (boyer_myrvold_planarity_test(
boost::boyer_myrvold_params::graph = K_4,
boost::boyer_myrvold_params::vertex_index_map = vindexMap))
std::cout << "K_4 is planar." << std::endl;
else
std::cout << "ERROR! K_4 should have been recognized as planar!"
<< std::endl;
It results in various cryptic template errors...
> 1>main.cpp
> 1>C:\Libraries\PCL-1.5.1\3rdParty\Boost\include\boost/graph/boyer_myrvold_planar_test.hpp(167)
> : error C2664:
> 'boost::boyer_myrvold_impl<Graph,VertexIndexMap,StoreOldHandlesPolicy,StoreEmbeddingPolicy>::boyer_myrvold_impl(const
> Graph &,VertexIndexMap)': Konvertierung des Parameters 2 von 'const
> boost::adj_list_vertex_property_map<Graph,ValueType,Reference,Tag>' in
> 'vertex_index_map_t' nicht möglich 1> with 1> [ 1>
> Graph=graph_t, 1> VertexIndexMap=vertex_index_map_t, 1>
> StoreOldHandlesPolicy=boost::graph::detail::no_old_handles, 1>
> StoreEmbeddingPolicy=boost::graph::detail::recursive_lazy_list 1>
> ] 1> and 1> [ 1> Graph=graph_t, 1>
> ValueType=boost::detail::error_property_not_found, 1>
> Reference=const boost::detail::error_property_not_found &, 1>
> Tag=boost::vertex_index_t 1> ] 1> Kein
> benutzerdefinierter Konvertierungsoperator verfügbar, der diese
> Konvertierung durchführen kann, oder der Operator kann nicht
> aufgerufen werden 1>
> C:\Libraries\PCL-1.5.1\3rdParty\Boost\include\boost/graph/boyer_myrvold_planar_test.hpp(259):
> Siehe Verweis auf die Instanziierung der gerade kompilierten
> Funktions-template "bool
> boost::boyer_myrvold_params::core::dispatched_boyer_myrvold<ArgumentPack>(const
> ArgumentPack &,boost::mpl::false_,boost::mpl::true_)". 1> with
> 1> [ 1>
> ArgumentPack=boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::embedding,const
> boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property>>,boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::graph,const
> boost::adjacency_list<boost::setS,boost::listS,boost::undirectedS,boost::no_property,boost::no_property>>,boost::parameter::aux::empty_arg_list>> 1> ] 1>
> C:\Libraries\PCL-1.5.1\3rdParty\Boost\include\boost/graph/boyer_myrvold_planar_test.hpp(281):
> Siehe Verweis auf die Instanziierung der gerade kompilierten
> Funktions-template "bool
> boost::boyer_myrvold_params::core::boyer_myrvold_planarity_test<boost::parameter::aux::arg_list<TaggedArg,Next>>(const ArgumentPack &)". 1> with 1> [ 1>
> TaggedArg=boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::embedding,const
> boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property>>,
> 1>
> Next=boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::graph,const
> boost::adjacency_list<boost::setS,boost::listS,boost::undirectedS,boost::no_property,boost::no_property>>,boost::parameter::aux::empty_arg_list>, 1>
> ArgumentPack=boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::embedding,const
> boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property>>,boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::graph,const
> boost::adjacency_list<boost::setS,boost::listS,boost::undirectedS,boost::no_property,boost::no_property>>,boost::parameter::aux::empty_arg_list>> 1> ] 1> .\src\main.cpp(135): Siehe Verweis auf die
> Instanziierung der gerade kompilierten Funktions-template "bool
> boost::boyer_myrvold_planarity_test<graph,boost::bgl_named_params<T,Tag,Base>>(const
> A0 &,const A1 &)". 1> with 1> [ 1>
> T=boost::associative_property_map<VertexDescMap>, 1>
> Tag=boost::vertex_index_t, 1> Base=boost::no_property, 1>
> A0=graph, 1>
> A1=boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property> 1> ]
In brief, it complains that it cannot convert/use it as I would like it.
How can I make it work?
What else do I have to give to the function?
Unfortunately, there are hardly boost examples for working with setS or listS as containers. Furthermore, I cannot use the property tags because this is part of a larger implementation and I need to keep the properties external.
I would be very happy if somebody has a suggestion.
The error message tells that you need to provide a vertex_index map; see the same problem answered here. Various ways to add the vertex_index map to adjacency_list are discussed here; in fact their problem is almost identical to yours.
In the following protocol buffer, how does one access the repeated fields in the extension from C++?
base.proto
message Base {
optional int32 id = 1;
repeated int32 ids = 2;
optional string name = 3;
repeated string names = 4;
extensions 1000 to 1999;
}
ext.proto
import "base.proto";
extend Base {
repeated string names = 1000;
optional int32 number = 1001;
repeated int32 numbers = 1002;
optional string name = 1003;
}
The following doesn't compile (in VS2010)
#include "base.pb.h"
#include "ext.pb.h"
using namespace ::google::protobuf;
int main(int argc, char *argv[])
{
Base b;
RepeatedPtrField<std::string> base_names = b.names(); // OK
RepeatedField<int> base_ids = b.ids(); // OK
int ext_number = b.GetExtension(number); // OK
std::string ext_name = b.GetExtension(name); // OK
assert( b.HasExtension(numbers) ); // OK
assert( b.HasExtension(names) ); // OK
int32 i = b.GetExtension(numbers); // ? Compiles but doesn't make sense.
RepeatedField<int32> ext_numbers = b.GetExtension(numbers); // compilation fails:
RepeatedPtrField<std::string> ext_names = b.GetExtension(names); // compilation fails:
return 0;
}
Compilation errors
1>test_proto.cpp(17): error C2440: 'initializing' : cannot convert from 'int' to 'google::protobuf::RepeatedField<Element>'
1> with
1> [
1> Element=google::protobuf::int32
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>\test_proto.cpp(18): error C2440: 'initializing' : cannot convert from 'const std::string' to 'google::protobuf::RepeatedPtrField<Element>'
1> with
1> [
1> Element=std::string
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
Thanks to Feng Xiao on the protobuf mailing list, use ExtensionSize(id) and GetExtension(id, index):
Base b;
int index = 0;
if (index < b.ExtensionSize(names))
{
std::string s_value = b.GetExtension(names, index);
}
I am using the MArgList class from the Maya API to retrieve arguments entered in the Maya command line. According to the class reference MArgList::get should be able to take an int or double as its second argument but it seems to be expecting a bool only and so throws a conversion error during compiling. The following is the code section and the errors generated. Any thoughts on what might be causing this would be much appreciated. The code was typed straight out of a tutorial on Maya plugin development, so it is a mystery why it is not working.
const int nPosts = 5;
const double radius = 0.5;
const double height = 5.0;
unsigned index;
index = args.flagIndex( "n", "number" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, nPosts );
unsigned index;
index = args.flagIndex( "r", "radius" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, radius );
unsigned index;
index = args.flagIndex( "h", "height" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, height );
1>Posts1Cmd.cpp(37): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const int' to 'bool &'
1>Posts1Cmd.cpp(39): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(42): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
1>Posts1Cmd.cpp(44): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(47): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you are going to get new values from the get function, you cannot have the target variables const.
Try
int nPosts = 5;
double radius = 0.5;
double height = 5.0;
Also, you should not declare a new index variable for each call. Just declare it once and reuse it.