2014-01-28 27 views
1

我有一個Win32控制檯應用程序,我已經將引用導入到Rx中。智能感知允許我做這個....RxCpp C++中的無效擴展

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 /主題和IObserver /觀察員。但是沒有IObservable。我對Cpp缺乏Rx文檔感到有些驚慌。我是否缺少任何明顯的資源?我試過Channel9,Google,Stackoverflow和Facebook組。這是我工作的C#代碼,我想用C++來處理它。該函數合併來自不同觀察資源的所有數據並將其列爲列表。

所以矩陣一出現源頭一,矩陣二出現源頭二。它們與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

我已嘗試之前在這裏提出,但沒有迴應。希望這會更有成效,現在我有更多的信息來說明我正在努力實現的目標。

謝謝。

+0

我不明白你怎麼把所有的這些命名空間...如何你究竟引用添加接收?我用nuget,並添加了rxcpp包。 –

回答

2

頂級命名空間是rxcpp,而不是System。爲了得到可觀察的結果,您需要:

#include "cpprx/rx.hpp" 
using namespace rxcpp; 
+0

是的,現在包括它,它的工程很好。雖然,現在我需要構建可觀察事件的擴展方法。 – WebSight

0

我發現這可以幫助很多。

但是我不確定誰用這個來創建擴展方法。在C++中甚至可能嗎?

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

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);     
      } 
      }); 
    }); 
} 

目的是獲得兩個可觀察源,其是受試者,在那裏它們由它們的ID成對在一起並一起推到OnNext方法一個可觀察。

問候,

丹尼爾

+0

C++中沒有擴展方法...只是使用一個免費函數。 –