1

Win32 コンソール アプリがあり、Rx への参照をインポートしました。インテリセンスは私がこれを行うことができます....

using namespace System::Reactive;
using namespace System::Reactive::Concurrency;
using namespace System::Reactive::Disposables;
using namespace System::Reactive::Joins;
using namespace System::Reactive::Linq;
using namespace System::Reactive::PlatformServices;
using namespace System::Reactive::Subjects;
using namespace System::Reactive::Threading;
using namespace System::Reactive::Threading;
using namespace System::Data::Linq;
using namespace System::Xml::Linq;

次に、ISubject/Subject や IObserver/Observer など、多数のクラスを利用できます。ただし、IObservable はありません。Cpp を使用した Rx のドキュメントがないことに少し不安を感じています。明らかなリソースが不足していますか?

Channel9、Google、Stackoverflow、Facebook のグループを試しました。これは私が作成した C# コードです。これを C++ で動作させたいと考えています。この関数は、さまざまな観測ソースからのすべてのデータをマージし、リストとして出力します。

したがって、マトリックス 1 はソース 1 から表示され、マトリックス 2 はソース 2 から表示されます。それらは id によって照合され、リストとして一緒にプッシュされます。

public static IObservable<IList<TSource>> MergeById<TSource>(this IObservable<TSource> source, Func<IList<TSource>, TSource> mergeFunc, Func<TSource, int> keySelector, int bufferCount)
{
   return Observable.Create<IList<TSource>>(o =>  
   {
     var buffer = new Dictionary<int, IList<TSource>>();
     return source.Subscribe<TSource>(i =>
          { 
             var index = keySelector(i);
             if (buffer.ContainsKey(index))
             {                  
               buffer[index].Add(i);
             }
             else
             {                                     
               buffer.Add(index, new List<TSource>(){i});                
             }
             if (buffer.Count==bufferCount)
             { 
               o.OnNext(mergeFunc(buffer[index]));    
               buffer.Remove(index);                
             }
          });
     });
}

ここでの助けは良いでしょう。必要なクラスの一部が見つからず、構文の他の側面が異なります。C++ での処理方法を示すソースまたは例はありますか。それらから推測することができるかもしれません。

問題の元の投稿はこちらです。

http://social.msdn.microsoft.com/Forums/en-US/58a25f70-a7b8-498b-ad7a-b57f3e1152da/rxcpp?forum=rx

以前こちらに問い合わせてみましたが、返答がありませんでした。これがもう少し実りあるものになることを願って、今私が達成しようとしていることについてより多くの情報を持っています.

ありがとうございました。

4

2 に答える 2

0

これは非常に役立つことがわかりました。

しかし、誰がこれを使用して拡張メソッドを作成するのかわかりません。それはC ++でも可能ですか?

http://social.msdn.microsoft.com/Forums/en-US/a500d5de-8c22-4222-829f-09ccd4c7920e/using-rx-from-ccx-metro-app?forum=rx&prof=必須

public static IObservable<IList<TSource>> MergeById<TSource>(this IObservable<TSource> source, Func<IList<TSource>, TSource> mergeFunc, Func<TSource, int> keySelector, int bufferCount)
{
   return Observable.Create<IList<TSource>>(o =>  
   {
     var buffer = new Dictionary<int, IList<TSource>>();
     return source.Subscribe<TSource>(i =>
          { 
             var index = keySelector(i);
             if (buffer.ContainsKey(index))
             {                  
               buffer[index].Add(i);
             }
             else
             {                                     
               buffer.Add(index, new List<TSource>(){i});                
             }
             if (buffer.Count==bufferCount)
             { 
               o.OnNext(mergeFunc(buffer[index]));    
               buffer.Remove(index);                
             }
          });
     });
}

目的は、サブジェクトである 2 つのオブザーバブル ソースを 1 つのオブザーバブルに取得し、ID でペアにして一緒に OnNext メソッドにプッシュすることです。

よろしく、

ダニエル

于 2014-01-28T21:57:20.990 に答える