flatbuffers sample gives non-standard syntax errors on compile in VS2017 - visual-studio-2017

I have been trying to reproduce something even simpler than the C++ sample in: https://github.com/google/flatbuffers/blob/master/samples/sample_binary.cpp
But I am getting some compile errors in VS2017 on the lines
//auto pos = compare->pos;
//auto two = compare->deviceType;
//auto desc = compare->description;
If I comment them out, it compiles and runs. If not, then I get the following errors:
Severity Code Description Project File Line Suppression State
Error C3867 'PNT::PseudoGPS::pos': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 50
Error C3867 'PNT::PseudoGPS::deviceType': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 51
Error C3867 'PNT::PseudoGPS::description': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 52
Here is the definition of my FBS object:
// Example IDL file for the PNT Schema
namespace PNT;
enum DeviceType:byte { IMU, VAN, GPS, MAGNAV, SOOP }
struct Vec3 {
x:float;
y:float;
z:float;
}
table PseudoGPS {
pos:Vec3;
deviceType:DeviceType = GPS;
description: string;
}
root_type PseudoGPS;
And here is the code that creates the FB object and then tries to access things (I am just exploring at this point, the code is not done).
flatbuffers::FlatBufferBuilder builder(1024);
auto position = PNT::Vec3(4.0, 5.0, 6.0);
auto description = builder.CreateString("Magnetic Postion");
auto msg = PNT::CreatePseudoGPS(builder, &position, PNT::DeviceType_MAGNAV, description);
builder.Finish(msg);
uint8_t *buf = builder.GetBufferPointer();
int size = builder.GetSize();
auto compare = PNT::GetPseudoGPS(buf);
auto pos = compare->pos;
auto two = compare->deviceType;
auto desc = compare->description;

compare->pos refers to an accessor function, try appending ()

Related

Wt - Example of QueryModel and WTableView?

I'm beginning with Wt, and after taking the basics of ORM module, I'm trying to show the results of a table (TableTags) with no success.
I have defined table TableTag as:
class TableTag
{
public:
static const unsigned int tableVersion = 1;
std::string name;
//Wt::Dbo::collection< Wt::Dbo::ptr<TablePost> > tablePosts;
TableTag();
~TableTag();
static void initTableRecords(Wt::Dbo::Session &_session);
template<class Action>
void persist(Action &_action)
{
Wt::Dbo::field(_action, name, "Name");
//Wt::Dbo::hasMany(_action, tablePosts, Wt::Dbo::ManyToMany, "Post");
}
};
typedef Wt::Dbo::collection< Wt::Dbo::ptr<TableTag> > TableTags;
and I'm begginning with a code similar to:
DDBBApp::setDDBBBackendAndSession(ddbbBackend_,ddbbSession_);
ddbbSession_.mapClass<TableTag>("TableTag");
{
Wt::Dbo::Transaction transaction(ddbbSession_);
Wt::Dbo::QueryModel<TableTag> * qmTags = new Wt::Dbo::QueryModel<TableTag>();
TableTags tags = ddbbSession_.find<TableTag>();
Wt::Dbo::Query<TableTag> qTag(ddbbSession_.find<TableTag>());
qmTags->setQuery(qTag);
WTableView * wtv = new WTableView();
wtv->setModel(qmTags);
}
but compiler complains with this error (VS2013, translated to English):
DDBBApp.cpp(54): error C2664:
'Wt::Dbo::Query::Query(Wt::Dbo::Session
&,const std::string &,const std::string &)' : argument 1 cannot be converted from 'Wt::Dbo::Query' to 'const
Wt::Dbo::Query &'
I've tried several constructors, variable types, etc... I know the point is close to this:
Wt::Dbo::QueryModel<TableTag> * qmTags = new Wt::Dbo::QueryModel<TableTag>();
Wt::Dbo::Query< Wt::Dbo::ptr<TableTag> > q1 = ddbbSession_.find<TableTag>();
qmTags->setQuery(qTag); //Error here
Wt::Dbo::Query<TableTag> q2 = ddbbSession_.find<TableTag>(); //Error here
qmTags->setQuery(q2);
But I'm not able to deal with this, I think the right way is 2nd one, according to the docu and snippets I've googled.
Can someone post a simple example so I can clarify how Wt works with this?
Wy the wall, I'm using Wt 3.3.3 under Win 8.1 + VS 2013.
Finally I figured it ^_^ thanks to: Not getting headers on WTableView with QueryModel
The rigth piece of code is as follows:
Wt::Dbo::QueryModel< Wt::Dbo::ptr<TableTag> > * qmTags1 = new Wt::Dbo::QueryModel< Wt::Dbo::ptr<TableTag> >();
qmTags1->setQuery(ddbbSession_.find<TableTag>());
qmTags1->addAllFieldsAsColumns();
WTableView * wtv1 = new WTableView();
wtv1->setModel(qmTags1);
this->root()->addWidget(wtv1);
Note: don't forget to use QueryModel->setQuery()!!

Array copy in parallel_for_each context

I’m very newbie in AMP C++. Everything works fine if I use ‘memcpy’ inside the ‘parallel_for_each’ function, but I do know it is not the best practice. I tried to use ‘copy_to’, but it raises an exception. Below follows a simplified code, focusing the issue, that I am having troubles. Thanks in advance.
typedef std::vector<DWORD> CArrDwData;
class CdataMatrix
{
public:
CdataMatrix(int nChCount) : m_ChCount(nChCount)
{
}
void SetSize(UINT uSize)
{
// MUST be multiple of m_ChCount*DWORD
ASSERT(uSize%sizeof(DWORD) == 0);
m_PackedLength = uSize/sizeof(DWORD);
m_arrChannels.resize(m_ChCount*m_PackedLength);
}
UINT GetChannelPackedLen() const
{
return m_PackedLength;
}
const LPBYTE GetChannelBuffer(UINT uChannel) const
{
CArrDwData::const_pointer cPtr = m_arrChannels.data() + m_PackedLength*uChannel;
return (const LPBYTE)cPtr;
}
public:
CArrDwData m_arrChannels;
protected:
UINT m_ChCount;
UINT m_PackedLength;
};
void CtypDiskHeader::ParalelProcess()
{
const int nJobs = 6;
const int nChannelCount = 3;
UINT uAmount = 250000;
int vch;
CArrDwData arrCompData;
// Check buffers sizes
ASSERT((~uAmount & 0x00000003) == 3); // DWORD aligned
const UINT uInDWSize = uAmount/sizeof(DWORD); // in size give in DWORDs
CdataMatrix arrChData(nJobs);
arrCompData.resize(nJobs*uInDWSize);
vector<int> a(nJobs);
for(vch = 0; vch < nJobs; vch++)
a[vch] = vch;
arrChData.SetSize(uAmount+16); // note: 16 bytes or 4 DWORDs larger than uInDWSize
accelerator_view acc_view = accelerator().default_view;
Concurrency::extent<2> eIn(nJobs, uInDWSize);
Concurrency::extent<2> eOut(nJobs, arrChData.GetChannelPackedLen());
array_view<DWORD, 2> viewOut(eOut, arrChData.m_arrChannels);
array_view<DWORD, 2> viewIn(eIn, arrCompData);
concurrency::parallel_for_each(begin(a), end(a), [&](int vch)
{
vector<DWORD>::pointer ptr = (LPDWORD)viewIn(vch).data();
LPDWORD bufCompIn = (LPDWORD)ptr;
ptr = viewOut(vch).data();
LPDWORD bufExpandedIn = (LPDWORD)ptr;
if(ConditionNotOk())
{
// Copy raw data bufCompIn to bufExpandedIn
// Works fine, but not the best way, I suppose:
memcpy(bufExpandedIn, bufCompIn, uAmount);
// Raises exception:
//viewIn(vch).copy_to(viewOut(vch));
}
else
{
// Some data processing here
}
});
}
It was my fault. In the original code, the extent of viewOut(vch) is a little bit larger than viewIn(vch) extent. Using this way, it raises an exception 'runtime_exception'. When catching it, it supplies the following message xcp.what() = "Failed to copy because extents do not match".
I fixed the code replacing the original code by: viewIn(vch).copy_to(viewOut(vch).section(viewIn(vch).extent));
It copies only the source extent, that is what I need. But only compiles without restricted AMP.
The has nothing to do with the parallel_for_each it looks like it is a known bug with array_view::copy_to. See the following post:
Curiosity about concurrency::copy and array_view projection interactions
You can fix this using an explicit view_as() instead. I believe in your case your code should look something like this.
viewIn(vch).copy_to(viewOut(vch));
// Becomes...
viewIn[vch].view_as<1>(concurrency::extent<1>(uInDWSize)).copy_to(viewOut(vch));
I can't compile your example so was unable to verify this but I was able to get an exception from similar code and fix it using view_as().
If you want to copy data within a C++ AMP kernel then you need to do it as assignment operations on a series of threads. The following code copies the first 500 elements of source into the smaller dest array.
array<int, 1> source(1000);
array<int, 1> dest(500);
parallel_for_each(source.extent, [=, &source, &dest](index<1> idx)
{
if (dest.extent.contains(idx))
dest[idx] = source[idx];
});

Resolve c++ pointer-to-member error in VS 2003

I have a c++ program that I'm trying to port from VS98 to VS2003 (incremental steps). One error that occurs throughout is "Error 2275"
For instance: k:\RR\chart\chartdlg.cpp(2025): error C2475: 'CRrDoc::cFldFilter' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
The offending code is shown below:
void CDataPage::OnBtnLabelField()
{
FLDID fid ;
LPMFFIELD f ;
CRrApp *pApp = (CRrApp *)AfxGetApp();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CRrDoc *pDoc = (CRrDoc *)pFrame->GetActiveDocument();
CSelectFieldDlg dlg;
//**************************************************
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter;
//dlg.ck = CRrDoc->*zcFldFilter;
//**************************************************
dlg.ck = pDoc->cFldFilter ;
dlg.TitleTextID = IDS_2676;
fid = (FLDID)dlg.DoModal();
if (fid != NOID)
{
f = pDoc->m_pComposite->mfbyndx(fid);
// find index
int i, iCount;
iCount = m_lboxLabel.GetCount();
for (i = 0; i < iCount; i++)
{
if(fid == m_lboxLabel.GetItemData(i))
{
m_lboxLabel.SetCurSel(i);
OnSelchangeComboLabel();
}
}
}
}
I tried handling it according to a Microsoft page: But that just generated a set of other problems (the commented code between the asterisks). Note that I also commented out the following line:
dlg.ck = pDoc->cFldFilter
Unfortunately, this leads to a new error: k:\RR\chart\chartdlg.cpp(2022): error C2440: 'initializing' : cannot convert from 'BOOL (__cdecl )(LPMFFIELD)' to 'BOOL CRrDoc:: '
The definition in the .H file looks like:
public:
static BOOL cFldFilter(LPMFFIELD f);
Any ideas how to handle the pointer-to-member issue?
since you have:
static BOOL CRrDoc::cFldFilter(LPMFFIELD f);
its type is not a member variable but a function:
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter; // doesn't work
BOOL (*zcFldFilter)(LPMFFIELD) = &CRrDoc::cFldFilter; // works
Since dlg.ck is of a correct type, you should do
dlg.ck = &CRrDoc::cFldFilter;

V8 compile error for basic example

I am trying to compile the hello world example for V8, and I keep running into a compile time error. Here is the code:
#include <v8/src/v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a string holding the JavaScript source code.
String source = String::New("Hi");
// Compile it.
Script script = Script::Compile(source) ;
// Run it.
Value result = script->Run();
// Convert the result to an ASCII string and display it.
String::AsciiValue ascii(result) ;
printf("%s\n", *ascii) ;
return 0;
}
This is the compile error:
error: conversion from ‘v8::Local<v8::String>’ to non-scalar type ‘v8::String’ requested
The error is for line 8 where it says: String source = String::New("Hi");
I have tried google'ing this error senseless, and cannot seem to find a fix for it that makes sense. Any ideas?
I have tried both:
svn checkout http://v8.googlecode.com/svn/trunk/ v8
and
svn checkout http://v8.googlecode.com/svn/branches/bleeding_edge/ v8
and get the same error for both.
Based on the error message, try:
Local<String> source = String::New("Hi");
try this code:
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<String> source = String::New("'Hello' + ', World!'");
Handle<Script> script = Script::Compile(source);
TryCatch trycatch;
Handle<Value> result = script->Run();
if ( result.IsEmpty() ) {
Handle<Value> excep = trycatch.Exception();
String::AsciiValue excep_str(excep);
printf("%s\n",*excep);
} else {
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
}
context.Dispose();
return 0;

How to coerce a xlTypeNum to double in C++ using Excel 2007 SDK

Well I am attempting to make my way through developing an Excel Add-in. I am trying small functions with the sample code in Excel 2007 SDK as as a guide. I am having difficulty with attempting to display a double type data in Excel. Assuming the UDF is called DisplayDouble() when the sample code is executed and a call is placed with an argument of real type data such as DisplayDouble(12.3) the sample code works yet if I attempt to use an argument that references a real type data from cell such as DisplayDouble(A1) where cell A1 in the Excel worksheet has the value 12.3 the sample code does not work
You can see the sample code below this paragraph. Any hints will help me move along the learning ladder
_declspec(dllexport) LPXLOPER12 WINAPI DisplayDouble (LPXLOPER12 n)
{
static XLOPER12 xResult;
XLOPER12 xlt;
int error = -1;
double d;
switch (n->xltype)
{
case xltypeNum:
d = (double)n->val.num;
if (max < 0)
error = xlerrValue;
xResult.xltype = xltypeNum;
xResult.val.num = d;
break;
case xltypeSRef:
error = Excel12f(xlCoerce, &xlt, 2, n, TempNum12(xltypeNum));
if (!error)
{
error = -1;
d = xlt.val.w;
xResult.xltype = xltypeNum;
xResult.val.num = d;
}
Excel12f(xlFree, 0, 1, &xlt);
break;
default:
error = xlerrValue;
break;
}
if ( error != - 1 )
{
xResult.xltype = xltypeErr;
xResult.val.err = error;
}
//Word of caution - returning static XLOPERs/XLOPER12s is not thread safe
//for UDFs declared as thread safe, use alternate memory allocation mechanisms
return(LPXLOPER12) &xResult;
}
looks like you coerced the value to xltypeNum but are then taking the integer value, with d = xlt.val.w rather than d = xlt.val.num