summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk Shoop <kirk.shoop@microsoft.com>2013-12-02 10:14:42 -0800
committerKirk Shoop <kirk.shoop@microsoft.com>2013-12-02 10:14:42 -0800
commite1190a782bc0ce57a7c6686dd29d1e873297edea (patch)
tree54a1196de64724fd0d94544bcf4bcfbad3abde99
parente93240d4f1cb01c77ddfc66de919971e8b9bc23b (diff)
downloadRxCpp-e1190a782bc0ce57a7c6686dd29d1e873297edea.tar.gz
Bug fixes and pretty-printing
-rw-r--r--.gitignore109
-rw-r--r--Rx/CPP/src/cpprx/rx-base.hpp36
-rw-r--r--Rx/CPP/src/cpprx/rx-includes.hpp3
-rw-r--r--Rx/CPP/src/cpprx/rx-scheduler.hpp6
4 files changed, 150 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..dd3a2a5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,109 @@
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+############
+## Mac
+############
+
+.DS_Store
+
+############
+## CMake
+############
+
+projects/CMake/*
+!projects/CMake/CMakelists.txt
diff --git a/Rx/CPP/src/cpprx/rx-base.hpp b/Rx/CPP/src/cpprx/rx-base.hpp
index 530935a..f8e6386 100644
--- a/Rx/CPP/src/cpprx/rx-base.hpp
+++ b/Rx/CPP/src/cpprx/rx-base.hpp
@@ -391,6 +391,7 @@ namespace rxcpp
protected:
VirtualTimeSchedulerBase()
: is_enabled(false)
+ , clock_now(0)
{
}
explicit VirtualTimeSchedulerBase(Absolute initialClock)
@@ -543,8 +544,8 @@ namespace rxcpp
public:
Recorded(long time, T value) : time(time), value(value) {
}
- long Time() {return time;}
- T Value() {return value;}
+ long Time() const {return time;}
+ const T& Value() const {return value;}
};
template<class T>
@@ -552,6 +553,12 @@ namespace rxcpp
return lhs.Time() == rhs.Time() && lhs.Value() == rhs.Value();
}
+ template<class T>
+ std::ostream& operator<< (std::ostream& out, const Recorded<T>& r) {
+ out << "@" << r.Time() << "-" << r.Value();
+ return out;
+ }
+
class Subscription
{
long subscribe;
@@ -562,14 +569,19 @@ namespace rxcpp
}
Subscription(long subscribe, long unsubscribe) : subscribe(subscribe), unsubscribe(unsubscribe) {
}
- long Subscribe() {return subscribe;}
- long Unsubscribe() {return unsubscribe;}
+ long Subscribe() const {return subscribe;}
+ long Unsubscribe() const {return unsubscribe;}
};
bool operator == (Subscription lhs, Subscription rhs) {
return lhs.Subscribe() == rhs.Subscribe() && lhs.Unsubscribe() == rhs.Unsubscribe();
}
+ std::ostream& operator<< (std::ostream& out, const Subscription& s) {
+ out << s.Subscribe() << "-" << s.Unsubscribe();
+ return out;
+ }
+
template<typename T>
struct Notification
{
@@ -579,6 +591,7 @@ namespace rxcpp
virtual ~Notification() {}
+ virtual void Out(std::ostream& out) =0;
virtual bool Equals(std::shared_ptr<Notification<T>> other) = 0;
virtual void Accept(std::shared_ptr<Observer<T>>) =0;
virtual void Accept(OnNext onnext, OnCompleted oncompleted, OnError onerror) =0;
@@ -587,6 +600,9 @@ namespace rxcpp
struct OnNextNotification : public Notification<T> {
OnNextNotification(T value) : value(std::move(value)) {
}
+ virtual void Out(std::ostream& out) {
+ out << "OnNext( " << value << ")";
+ }
virtual bool Equals(std::shared_ptr<Notification<T>> other) {
bool result = false;
other->Accept([this, &result](T value) { result = this->value == value;}, [](){}, [](std::exception_ptr){});
@@ -610,6 +626,9 @@ namespace rxcpp
struct OnCompletedNotification : public Notification<T> {
OnCompletedNotification() {
}
+ virtual void Out(std::ostream& out) {
+ out << "OnCompleted()";
+ }
virtual bool Equals(std::shared_ptr<Notification<T>> other) {
bool result = false;
other->Accept([](T) {}, [&result](){result = true;}, [](std::exception_ptr){});
@@ -632,6 +651,9 @@ namespace rxcpp
struct OnErrorNotification : public Notification<T> {
OnErrorNotification(std::exception_ptr ep) : ep(ep) {
}
+ virtual void Out(std::ostream& out) {
+ out << "OnError()";
+ }
virtual bool Equals(std::shared_ptr<Notification<T>> other) {
bool result = false;
// not trying to compare exceptions
@@ -684,6 +706,12 @@ namespace rxcpp
}
template<class T>
+ std::ostream& operator<< (std::ostream& out, const std::shared_ptr<Notification<T>>& n) {
+ n->Out(out);
+ return out;
+ }
+
+ template<class T>
struct TestableObserver : public Observer<T>
{
virtual std::vector<Recorded<std::shared_ptr<Notification<T>>>> Messages() =0;
diff --git a/Rx/CPP/src/cpprx/rx-includes.hpp b/Rx/CPP/src/cpprx/rx-includes.hpp
index 743a86f..4ef0221 100644
--- a/Rx/CPP/src/cpprx/rx-includes.hpp
+++ b/Rx/CPP/src/cpprx/rx-includes.hpp
@@ -12,6 +12,9 @@
#include <stdlib.h>
+#include <iostream>
+#include <iomanip>
+
#include <exception>
#include <functional>
#include <memory>
diff --git a/Rx/CPP/src/cpprx/rx-scheduler.hpp b/Rx/CPP/src/cpprx/rx-scheduler.hpp
index 108556b..f4216c5 100644
--- a/Rx/CPP/src/cpprx/rx-scheduler.hpp
+++ b/Rx/CPP/src/cpprx/rx-scheduler.hpp
@@ -702,6 +702,12 @@ namespace rxcpp
return Subscription(subscribe, unsubscribe);
}
+ template<class Item, size_t size>
+ static
+ auto ToVector(const Item (&arr) [size]) -> std::vector<Item> {
+ return std::vector<Item>(std::begin(arr), std::end(arr));
+ }
+
private:
~Messages();
};