iOS:使用示例Poco :: BinaryReader&波科::的BinaryWriter

时间:2012-06-07 06:33:36

标签: c++ objective-c ios poco-libraries

有人可以在iOS 5.x上显示使用旁观流的使用情况Poco::BinaryReaderPoco::BinaryWriter的示例 - > Objective-C ++?

昨天我发送了关于“How to create and use C++ classes”的问题,但我的上述问题没有回答。

Poco社区论坛和OpenFrameworks论坛看起来像死了,所以我在这里。

感谢。

1 个答案:

答案 0 :(得分:0)

好的,没有人想帮忙。

我自己在上帝的帮助下做到了。

  

下载OpenFrameworks并配置目标项目;

代码示例:

#import "AppDelegate.h"
#import "Poco/MemoryStream.h"
#import "Poco/BinaryWriter.h"
#import "Poco/BinaryReader.h"

@implementation AppDelegate{
    Poco::BinaryWriter *_myBinaryWriter;
    Poco::BinaryReader *_myBinaryReader;
}

@synthesize window = _window;

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.rootViewController = [[UIViewController new] autorelease];

    int bufferSize = 512;    
    char *_buffer = (char *)malloc(bufferSize);

    // >> WRITE BLOCK <<   
    Poco::MemoryOutputStream *outStream = new Poco::MemoryOutputStream(_buffer, bufferSize);

    _myBinaryWriter = new Poco::BinaryWriter(*outStream);
    (*_myBinaryWriter) << 1234567890;
    (*_myBinaryWriter) << (std::string)"some string";
    (*_myBinaryWriter) << 3.14f;
    delete(_myBinaryWriter);
    delete(outStream);

    // >> READ BLOCK <<   
    Poco::MemoryInputStream *inStream = new Poco::MemoryInputStream(_buffer, bufferSize);

    _myBinaryReader = new Poco::BinaryReader(*inStream);

    int i = 0;
    std::string s;
    float f = .0f;

    (*_myBinaryReader) >> i >> s >> f;
    delete(_myBinaryReader);
    delete(inStream);

    NSLog(@"ReadInt = '%i'", i);
    NSLog(@"ReadString = '%@'", [NSString stringWithUTF8String:s.c_str()]);
    NSLog(@"ReadFloat = '%f'", f);

    [self.window makeKeyAndVisible];
    return YES;
}

@end

祝我有个美好的一天:)