Hi,
thanks for your comment, I see a little bit clearer now. But also your example don't compile (msvc) or crashes with mingw.
My original "problem" is to make a library call to astyle (because I had rearrange my plugin last time and want to release a new version). The idea was to encapsulate all astyle stuff in a single class, with simple returns the formatted source code and it should be used in parallel to speed up things for future. I can make a work around with a static error function and a mutex and grab the error string inside formatedText(), but I it would be nicer to directly use a member function (if possible).
QString ASInstance
::formatedText(const QString
& text
) {
m_error = false;
const char* textOut = AStyleMain(baIn.constData(),
m_options.constData(),
/* MAGIC goes here, must be fpError */,
&ArtisticStyle::Internal::ASInstance::memoryAlloc);
delete [] textOut;
return formattedText;
}
void ASInstance::errorHandler(int number, const char* message)
{
m_error = true;
m_errorNumber = number;
}
QString ASInstance::formatedText(const QString& text)
{
m_error = false;
QByteArray baIn = text.toUtf8();
const char* textOut = AStyleMain(baIn.constData(),
m_options.constData(),
/* MAGIC goes here, must be fpError */,
&ArtisticStyle::Internal::ASInstance::memoryAlloc);
QString formattedText = QString::fromUtf8(textOut);
delete [] textOut;
return formattedText;
}
void ASInstance::errorHandler(int number, const char* message)
{
m_error = true;
m_errorNumber = number;
m_errorMessage = QString(message);
}
To copy to clipboard, switch view to plain text mode
and from astyle.h
typedef void (STDCALL* fpError)(int, const char*); // pointer to callback error handler
extern "C" EXPORT char* STDCALL AStyleMain(const char*, const char*, fpError, fpAlloc);
typedef void (STDCALL* fpError)(int, const char*); // pointer to callback error handler
extern "C" EXPORT char* STDCALL AStyleMain(const char*, const char*, fpError, fpAlloc);
To copy to clipboard, switch view to plain text mode
Bookmarks