stlab.adobe.com Adobe Systems Incorporated

counter.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /******************************************************************************/
00008 
00009 #ifndef ADOBE_COUNTER_HPP
00010 #define ADOBE_COUNTER_HPP
00011 
00012 /******************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <boost/noncopyable.hpp>
00017 
00018 #include <adobe/implementation/atomic_primitives.hpp>
00019 
00020 /******************************************************************************/
00021 
00022 namespace adobe {
00023 
00024 /******************************************************************************/
00025 
00074 class counter_t
00075 #if !defined(ADOBE_NO_DOCUMENTATION)
00076     : boost::noncopyable
00077 #endif
00078 {
00079 public:
00080     counter_t()
00081     {
00082         count_m = implementation::atomic_t::value_type(1);
00083     }
00084 
00085     void increment()
00086     {
00087         ++count_m;
00088     }
00089 
00090     bool decrement()
00091     {
00092         return --count_m == implementation::atomic_t::value_type(0);
00093     }
00094 
00095     bool is_one() const
00096     {
00097         return count_m == implementation::atomic_t::value_type(1);
00098     }
00099 
00100 private:
00101     implementation::atomic_t::type count_m;
00102 };
00103 
00104 /******************************************************************************/
00105 
00106 } // namespace adobe
00107 
00108 /******************************************************************************/
00109 // ADOBE_COUNTER_HPP
00110 #endif
00111 
00112 /******************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google