我需要這個類的C++轉換爲一個Python模塊,並給出錯誤 /* * arexcrypt.h/C++類與痛飲Python模塊
#ifndef AREXCRYPT_H
#define AREXCRYPT_H
//Qt
#include <QString>
#include <QVector>
#include <QFlags>
//App
#include "singleton.h"
class ArexCrypt: public Singleton<ArexCrypt>
{
friend class Singleton<ArexCrypt>;
public:
enum Compression {
IfReducedCompress,
AlwaysCompress,
NeverCompress
};
enum IntegrityCheck {
NoCheck,
ChecksumCheck,
HashCheck
};
enum Error {
NoneError,
NoKeyError,
NoDataError,
UnknownVersionError,
IntegrityError
};
enum CryptoFlag{
NoneFlag = 0,
CompressedFlag = 0x01,
ChecksumFlag = 0x02,
HashFlag = 0x04
};
Q_DECLARE_FLAGS(CryptoFlags, CryptoFlag);
void setKey(quint64 pKey);
Compression CompressionMode() const;
void setCompressionMode(Compression pMode);
IntegrityCheck IntegrityProtectionMode() const;
void setIntegrityProtectionMode(IntegrityCheck pMode);
Error LastError() const;
//METHODS
QString EncryptToString(const QString &pText);
QString DecryptToString(const QString &pEncryptedText);
QString GenerateIntegrityKey(const QString &pText);
bool CheckIntegrityKey(const QString &pText);
private:
//Data
quint64 key;
QVector<char> keyParts;
Compression compressionMode;
IntegrityCheck protectionMode;
Error lastError;
bool showConsoleMessages;
//CONTRUCTORS AND DESTROYERS
ArexCrypt();
//METHODS
void SplitKey();
void EncryptArray(QByteArray &pArray);
void DecryptArray(QByteArray &pArray);
QByteArray GenerateIntegrityData(QByteArray dataArray, CryptoFlags &flags);
QByteArray EncryptToByteArray(QByteArray pTextArray);
QByteArray DecryptToByteArray(QByteArray pEncryptedArray);
//OTHERS
QString EncryptToString(QByteArray pTextArray);
QString DecryptToString(QByteArray pEncryptedArray);
QByteArray EncryptToByteArray(const QString &pText);
QByteArray DecryptToByteArray(const QString &pEncryptedText);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ArexCrypt::CryptoFlags);
#endif // AREXCRYPT_H
/arexcrypt.i/
/* arexcrypt.i */
%module arexcrypt
%{
#include "arexcrypt.h"
%}
%import "singleton.i"
%include std_string.i
%include std_vector.i
%include stl.i
%include "arexcrypt.h"
/* singleton.h */
#ifndef SINGLETON_H
#define SINGLETON_H
template <typename T> struct Singleton
{
static T &instance()
{
static T m_instance;
return m_instance;
}
protected:
Singleton() { }
};
#endif // SINGLETON_H
/* singleton.i */
/* singleton.i */
%module singleton
%{
#include "singleton.h"
%}
%include "singleton.h"
%template(intSingleton) Singleton<int>;
然後當我轉換爲蟒我得到這個控制檯
痛飲-C++ -python arexcrypt.i
arexcrypt.h(11 ):警告401:關於基類「Singleton < ArexCrypt>」未知。忽略。 arexcrypt.h(11):警告401:您可能忘記使用%模板實例化'Singleton < ArexCrypt>'。 arexcrypt.h(40):警告504:函數ArexCrypt :: Q_DECLARE_FLAGS(CryptoFlags,ArexCrypt :: CryptoFlag)必須具有返回類型。忽略。 arexcrypt.h(81):警告503:除非重命名爲有效的標識符,否則無法包裝「ArexCrypt :: CryptoFlags」。
GCC -c arexcrypt_wrap.cxx -o arexcrypt.o -fpic -std =的C++ 0x
我得到這個
arexcrypt_wrap.cxx:1: warning: -fpic ignored for target (all code is position independent)
arexcrypt_wrap.cxx:171:21: error: Python.h: No such file or directory
arexcrypt_wrap.cxx:3027:4: error: #error "This python version requires swig to be run with the '-classic' option"
In file included from arexcrypt_wrap.cxx:3124:
arexcrypt.h:5:19: error: QString: No such file or directory
arexcrypt.h:6:19: error: QVector: No such file or directory
arexcrypt.h:7:18: error: QFlags: No such file or directory
arexcrypt_wrap.cxx:801: error: 'PyObject' was not declared in this scope
arexcrypt_wrap.cxx:801: error: 'str' was not declared in this scope
arexcrypt_wrap.cxx:802: error: expected ',' or ';' before '{' token
arexcrypt_wrap.cxx:825: error: expected initializer before '*' token
arexcrypt_wrap.cxx:851: error: expected initializer before '*' token
arexcrypt_wrap.cxx:905: error: expected initializer before '*' token
arexcrypt_wrap.cxx:920: error: 'inquiry' does not name a type
arexcrypt_wrap.cxx:921: error: 'intargfunc' does not name a type
arexcrypt_wrap.cxx:922: error: 'intintargfunc' does not name a type
arexcrypt_wrap.cxx:923: error: 'intobjargproc' does not name a type
arexcrypt_wrap.cxx:924: error: 'intintobjargproc' does not name a type
arexcrypt_wrap.cxx:925: error: 'getreadbufferproc' does not name a type
arexcrypt_wrap.cxx:926: error: 'getwritebufferproc' does not name a type
arexcrypt_wrap.cxx:927: error: 'getsegcountproc' does not name a type
arexcrypt_wrap.cxx:928: error: 'getcharbufferproc' does not name a type
arexcrypt_wrap.cxx:929: error: 'PyObject' was not declared in this scope
arexcrypt_wrap.cxx:929: error: 'x' was not declared in this scope
arexcrypt_wrap.cxx:929: error: expected primary-expression before 'void'
arexcrypt_wrap.cxx:929: error: initializer expression list treated as compound expression
arexcrypt_wrap.cxx:930: error: expected ',' or ';' before '{' token
In file included from c:\mingw64_4.4.6\bin\../lib/gcc/x86_64-w64-mingw32/4.4.6/../../../../x86_64-w64-mingw32/include/c++/4.4.6/stdexcept:38,
from arexcrypt_wrap.cxx:3051:
c:\mingw64_4.4.6\bin\../lib/gcc/x86_64-w64-mingw32/4.4.6/../../../../x86_64-w64-mingw32/include/c++/4.4.6/exception:35: error: expected declaration before end of line
有誰知道什麼可能要去我做錯了
遺憾我錯過的東西 –
/*的#ifndef SINGLETON_H 的#define SINGLETON_H 模板結構辛格爾頓 { \t靜態T&實例() \t { \t \t靜態牛逼m_instance; \t \t return m_instance; \t} protected: \t Singleton(){} }; #endif // SINGLETON_H * / –