|
From: <bo...@us...> - 2009-05-02 00:17:54
|
Revision: 400
http://gearbox.svn.sourceforge.net/gearbox/?rev=400&view=rev
Author: borax00
Date: 2009-05-02 00:16:14 +0000 (Sat, 02 May 2009)
Log Message:
-----------
Implemented peek()
Modified Paths:
--------------
gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/store.h
gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/test/storetest.cpp
Modified: gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/store.h
===================================================================
--- gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/store.h 2009-05-01 21:42:20 UTC (rev 399)
+++ gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/store.h 2009-05-02 00:16:14 UTC (rev 400)
@@ -62,6 +62,11 @@
//! raises an gbxutilacfr::Exception exception.
void get( Type & obj ) const;
+ //! Returns the contents of the Store. This operation does not modify anything, i.e. the
+ //! contents of the store remain "new" (unlike get()). Calls to peek() when the Store is empty
+ //! raises an gbxutilacfr::Exception exception.
+ void peek( Type & obj ) const;
+
/*!
@brief Waits until the next update and returns the new value.
If the Store is empty, @ref getNext blocks until the Store is set and returns the new value.
@@ -146,6 +151,21 @@
}
template<class Type>
+void Store<Type>::peek( Type & obj ) const
+{
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ if ( !isEmpty_ )
+ {
+ internalGet( obj );
+ // do NOT set isNewData_ to false
+ }
+ else
+ {
+ throw gbxutilacfr::Exception( ERROR_INFO, "trying to read from an empty Store." );
+ }
+}
+
+template<class Type>
int Store<Type>::getNext( Type & obj, int timeoutMs ) const
{
// special case: infinite wait time
Modified: gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/test/storetest.cpp
===================================================================
--- gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/test/storetest.cpp 2009-05-01 21:42:20 UTC (rev 399)
+++ gearbox/trunk/src/gbxsickacfr/gbxiceutilacfr/test/storetest.cpp 2009-05-02 00:16:14 UTC (rev 400)
@@ -34,6 +34,20 @@
}
cout<<"ok"<<endl;
+ cout<<"testing peek() ... ";
+ // call peek on an empty stomach
+ try
+ {
+ store.peek( data );
+ cout<<"failed. empty store, should've caught exception"<<endl;
+ return EXIT_FAILURE;
+ }
+ catch ( const gbxutilacfr::Exception & )
+ {
+ ; // ok
+ }
+ cout<<"ok"<<endl;
+
cout<<"testing getNext() ... ";
if ( store.getNext( data, 50 )==0 ) {
cout<<"failed. not expecting anybody setting the store"<<endl;
@@ -58,6 +72,28 @@
}
cout<<"ok"<<endl;
+ cout<<"testing peek() ... ";
+ try
+ {
+ store.peek( copy );
+ }
+ catch ( const gbxutilacfr::Exception & )
+ {
+ cout<<"failed. should be a non-empty store."<<endl;
+ return EXIT_FAILURE;
+ }
+ if ( data!=copy )
+ {
+ cout<<"failed. expecting an exact copy of the data."<<endl;
+ cout<<"\tin="<<data<<" out="<<copy<<endl;
+ return EXIT_FAILURE;
+ }
+ if ( store.isEmpty() || !store.isNewData() ) {
+ cout<<"failed. expecting a non-empty new store."<<endl;
+ return EXIT_FAILURE;
+ }
+ cout<<"ok"<<endl;
+
cout<<"testing get() ... ";
try
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|