0

Poco::BinaryReaderPoco::BinaryWriterの iOS 5.x -> Objective-C++ でバイナリ ストリームを使用する例を教えてもらえますか?

昨日、「C++ クラスの作成方法と使用方法」に関する質問を送信しましたが、上記の質問に対する回答ではありません。

Poco コミュニティ フォーラムと OpenFramework フォーラムが死んでいるように見えるので、私はここにいます。

ありがとう。

4

1 に答える 1

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

私は良い一日を持っています:)

于 2012-06-07T09:24:05.400 に答える