有人成功将 SpeakHere 移植到 ARC 吗?

发布于 2024-12-03 07:12:23 字数 2258 浏览 3 评论 0原文

当我尝试集成 SpeakHere 中的录制/播放代码时,我的编译器报告了很多错误。 我遵循建议使用 .mm 文件来包含 cpp 包含文件,唯一的例外是我使用启用了 ARC 的 iOS 5。

我的代码是:

//header file
#import "AQPlayer.h"
#import "AQRecorder.h"

@interface MyClass : NSObject {

UIButton *record;
UIButton *cancel;
UIButton *stop;
UIButton *play;

//
AQPlayer*                   player;
AQRecorder*                 recorder;
BOOL                        playbackWasInterrupted;
BOOL                        playbackWasPaused;

CFStringRef                 recordFilePath; 
}

@property (nonatomic, retain) IBOutlet DrawerAudioNote *dnote;
@property (nonatomic, retain) IBOutlet UIButton *record;
@property (nonatomic, retain) IBOutlet UIButton *cancel;
@property (nonatomic, retain) IBOutlet UIButton *stop;
@property (nonatomic, retain) IBOutlet UIButton *play;

- (IBAction) doRecord:(id)sender;
- (IBAction) doStop:(id)sender;
- (IBAction) doCancel:(id)sender;
- (IBAction) doPlay:(id)sender;

//
@property (readonly)            AQPlayer            *player;
@property (readonly)            AQRecorder          *recorder;

//.mm file (no compile error)
@import "MyClass.h"
@implementation MyClass

@synthesize record, cancel, stop, play;
@synthesize playbackWasInterrupted;
@synthesize player, recorder;

//CAXException.h (an example cpp file with compile errors)
......
class CAX4CCString { 
//ERROR: Expect ';' after top level declarator
//ERROR: Unknown type name; do you mean 'Class'?
public:
    CAX4CCString(OSStatus error) {
        // see if it appears to be a 4-char-code
        char *str = mStr;
        *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
        if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {         
            str[0] = str[5] = '\'';
            str[6] = '\0';
        } else if (error > -200000 && error < 200000)
            // no, format it as an integer
            sprintf(str, "%d", (int)error);
        else
            sprintf(str, "0x%x", (int)error);
    }
    const char *get() const { return mStr; }
    operator const char *() const { return mStr; }
private:
    char mStr[16];
};

通过“CAX4CCString”类中的编译错误,编译器似乎不明白他正在处理 CPP 文件。 我知道我会在某个地方错过一些东西,有人可以指出吗?

预先感谢,

肖恩

My compiler reported a lot of error when I were trying to integrate record/play code from SpeakHere.
I have followed suggestions to use a .mm file to include cpp include file, the only exception is I am using iOS 5 with ARC enabled.

My code is:

//header file
#import "AQPlayer.h"
#import "AQRecorder.h"

@interface MyClass : NSObject {

UIButton *record;
UIButton *cancel;
UIButton *stop;
UIButton *play;

//
AQPlayer*                   player;
AQRecorder*                 recorder;
BOOL                        playbackWasInterrupted;
BOOL                        playbackWasPaused;

CFStringRef                 recordFilePath; 
}

@property (nonatomic, retain) IBOutlet DrawerAudioNote *dnote;
@property (nonatomic, retain) IBOutlet UIButton *record;
@property (nonatomic, retain) IBOutlet UIButton *cancel;
@property (nonatomic, retain) IBOutlet UIButton *stop;
@property (nonatomic, retain) IBOutlet UIButton *play;

- (IBAction) doRecord:(id)sender;
- (IBAction) doStop:(id)sender;
- (IBAction) doCancel:(id)sender;
- (IBAction) doPlay:(id)sender;

//
@property (readonly)            AQPlayer            *player;
@property (readonly)            AQRecorder          *recorder;

//.mm file (no compile error)
@import "MyClass.h"
@implementation MyClass

@synthesize record, cancel, stop, play;
@synthesize playbackWasInterrupted;
@synthesize player, recorder;

//CAXException.h (an example cpp file with compile errors)
......
class CAX4CCString { 
//ERROR: Expect ';' after top level declarator
//ERROR: Unknown type name; do you mean 'Class'?
public:
    CAX4CCString(OSStatus error) {
        // see if it appears to be a 4-char-code
        char *str = mStr;
        *(UInt32 *)(str + 1) = CFSwapInt32HostToBig(error);
        if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {         
            str[0] = str[5] = '\'';
            str[6] = '\0';
        } else if (error > -200000 && error < 200000)
            // no, format it as an integer
            sprintf(str, "%d", (int)error);
        else
            sprintf(str, "0x%x", (int)error);
    }
    const char *get() const { return mStr; }
    operator const char *() const { return mStr; }
private:
    char mStr[16];
};

By compilation errors in class 'CAX4CCString', the compiler seems does not understand he is working on CPP file.
I know I would have missed something in somewhere, anyone can point out?

Thanks in advance,

Sean

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心舞飞扬 2024-12-10 07:12:23

为什么不对特定文件禁用 ARC?除了有问题的文件外,您的项目仍保留在 ARC 中。将 -fno-objc-arc 添加到您不希望使用 ARC 的文件的编译器标志中。在 Xcode 中,您可以在您的目标 -> 下执行此操作构建阶段 ->编译源。

Why not disable ARC for specific files? Your project remains with ARC, except the problematic files. Add -fno-objc-arc to the compiler flags for the files you don't want with ARC. In Xcode, you can do this under your target -> Build Phases -> Compile Sources.

扎心 2024-12-10 07:12:23

声明 C++ 类

class CAX4CCString { 

您正在Objective-C 类 MyClass 中 。我担心 Objective-C 不支持这一点。

我认为你可以在全局范围内声明CAX4CCString,然后从你的 Objective-C 类中实例化并使用它:

//.mm file

class CAX4CCString { 
   ....
};


@implementation MyClass

@synthesize record, cancel, stop, play;
@synthesize playbackWasInterrupted;
@synthesize player, recorder;
...
   <do something with CAX4CCString>
@end

You are declaring the C++ class

class CAX4CCString { 

inside of the Objective-C class MyClass. I fear this is not supported by Objective-C.

What I think you could so is declare CAX4CCString in the global scope and then instantiate and use it from your Objective-C class:

//.mm file

class CAX4CCString { 
   ....
};


@implementation MyClass

@synthesize record, cancel, stop, play;
@synthesize playbackWasInterrupted;
@synthesize player, recorder;
...
   <do something with CAX4CCString>
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文