[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8518 - in usrp2/trunk/host-ng: apps include/usrp2 lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8518 - in usrp2/trunk/host-ng: apps include/usrp2 lib |
Date: |
Wed, 28 May 2008 14:23:56 -0600 (MDT) |
Author: jcorgan
Date: 2008-05-28 14:23:55 -0600 (Wed, 28 May 2008)
New Revision: 8518
Modified:
usrp2/trunk/host-ng/apps/test_usrp2.cc
usrp2/trunk/host-ng/include/usrp2/usrp2.h
usrp2/trunk/host-ng/lib/usrp2.cc
Log:
Refactor factory creation technique and use pimpl idiom.
Modified: usrp2/trunk/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-05-28 16:53:43 UTC (rev
8517)
+++ usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-05-28 20:23:55 UTC (rev
8518)
@@ -21,11 +21,13 @@
#endif
#include <usrp2/usrp2.h>
+#include <iostream.h>
int
main(int argc, char **argv)
{
- usrp2::usrp2_sptr u2 = usrp2::make_usrp2();
-
+ usrp2::usrp2::sptr u2 = usrp2::usrp2::make("eth0");
+ std::cout << u2->foo(1) << std::endl;
+
return 0;
}
Modified: usrp2/trunk/host-ng/include/usrp2/usrp2.h
===================================================================
--- usrp2/trunk/host-ng/include/usrp2/usrp2.h 2008-05-28 16:53:43 UTC (rev
8517)
+++ usrp2/trunk/host-ng/include/usrp2/usrp2.h 2008-05-28 20:23:55 UTC (rev
8518)
@@ -24,23 +24,38 @@
namespace usrp2 {
-// Shared pointer to usrp2::usrp2
-class usrp2;
-typedef boost::shared_ptr<usrp2> usrp2_sptr;
-
-// Factory function to return a new instance of usrp2::usrp2
-usrp2_sptr make_usrp2();
-
-class usrp2
+class usrp2 : boost::noncopyable
{
private:
- // Only factory function can instantiate this class
- usrp2();
- friend usrp2_sptr make_usrp2();
+ // Only usrp2::make factory function can instantiate this class
+ usrp2(const std::string &ifc, const std::string &addr);
+ class impl;
+ std::auto_ptr<impl> d_impl;
+
public:
+ /*!
+ * Shared pointer to this class
+ */
+ typedef boost::shared_ptr<usrp2> sptr;
+
+ /*!
+ * Static function to return an instance of usrp2 as a shared pointer
+ *
+ * \param ifc Network interface name, e.g., "eth0"
+ * \param addr Network mac address, e.g., "01:02:03:04:05:06" or "05:06",
+ * default is auto-select
+ */
+ static sptr make(const std::string &ifc, const std::string &addr="");
+
+ /*!
+ * Class destructor
+ */
~usrp2();
+ // -------------------------------------------------------------------
+
+ int foo(int bar);
};
};
Modified: usrp2/trunk/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/lib/usrp2.cc 2008-05-28 16:53:43 UTC (rev 8517)
+++ usrp2/trunk/host-ng/lib/usrp2.cc 2008-05-28 20:23:55 UTC (rev 8518)
@@ -21,21 +21,62 @@
#endif
#include <usrp2/usrp2.h>
+#include <iostream>
namespace usrp2 {
-usrp2_sptr
-make_usrp2()
+// --- Private implementation class -------------------------------------
+
+class usrp2::impl
{
- return usrp2_sptr(new usrp2());
+public:
+ impl(const std::string &ifc, const std::string &addr);
+
+ int foo(int bar);
+};
+
+// --- Object creation glue ---------------------------------------------
+
+// Shared pointer factory function, wraps constructor call
+usrp2::sptr
+usrp2::make(const std::string &ifc, const std::string &addr)
+{
+ return usrp2::sptr(new usrp2(ifc, addr));
}
-usrp2::usrp2()
+// Private constructor. Sole function is to create an impl.
+usrp2::usrp2(const std::string &ifc, const std::string &addr)
+ : d_impl(new usrp2::impl(ifc, addr))
{
+ // NOP
}
+// Public class destructor. d_impl will auto-delete.
usrp2::~usrp2()
{
+ // NOP
}
+// --- Proxy methods ----------------------------------------------------
+
+int
+usrp2::foo(int bar)
+{
+ return d_impl->foo(bar);
}
+
+// --- Private implementation -------------------------------------------
+
+// Impl constructor
+usrp2::impl::impl(const std::string &ifc, const std::string &addr)
+{
+ std::cerr << "usrp2: constructor" << std::endl;
+}
+
+int
+usrp2::impl::foo(int bar)
+{
+ return bar+1;
+}
+
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8518 - in usrp2/trunk/host-ng: apps include/usrp2 lib,
jcorgan <=