1*1be3ed10SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*1be3ed10SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1be3ed10SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1be3ed10SAndrew Rist * distributed with this work for additional information 6*1be3ed10SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1be3ed10SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1be3ed10SAndrew Rist * "License"); you may not use this file except in compliance 9*1be3ed10SAndrew Rist * with the License. You may obtain a copy of the License at 10*1be3ed10SAndrew Rist * 11*1be3ed10SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*1be3ed10SAndrew Rist * 13*1be3ed10SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1be3ed10SAndrew Rist * software distributed under the License is distributed on an 15*1be3ed10SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1be3ed10SAndrew Rist * KIND, either express or implied. See the License for the 17*1be3ed10SAndrew Rist * specific language governing permissions and limitations 18*1be3ed10SAndrew Rist * under the License. 19*1be3ed10SAndrew Rist * 20*1be3ed10SAndrew Rist *************************************************************/ 21*1be3ed10SAndrew Rist 22*1be3ed10SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _VOS_REFERNCE_HXX_ 25cdf0e10cSrcweir #define _VOS_REFERNCE_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir # include <vos/types.hxx> 28cdf0e10cSrcweir # include <osl/interlck.h> 29cdf0e10cSrcweir # include <vos/object.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace vos 32cdf0e10cSrcweir { 33cdf0e10cSrcweir 34cdf0e10cSrcweir /** Interface for refernce-counting 35cdf0e10cSrcweir */ 36cdf0e10cSrcweir class IReference 37cdf0e10cSrcweir { 38cdf0e10cSrcweir public: 39cdf0e10cSrcweir IReference()40cdf0e10cSrcweir IReference() { } ~IReference()41cdf0e10cSrcweir virtual ~IReference() { } 42cdf0e10cSrcweir 43cdf0e10cSrcweir typedef oslInterlockedCount RefCount; 44cdf0e10cSrcweir 45cdf0e10cSrcweir virtual RefCount SAL_CALL acquire()=0; 46cdf0e10cSrcweir virtual RefCount SAL_CALL release()=0; 47cdf0e10cSrcweir 48cdf0e10cSrcweir virtual RefCount SAL_CALL referenced() const=0; 49cdf0e10cSrcweir }; 50cdf0e10cSrcweir 51cdf0e10cSrcweir class ORefCount 52cdf0e10cSrcweir { 53cdf0e10cSrcweir public: 54cdf0e10cSrcweir typedef IReference::RefCount RefCount; 55cdf0e10cSrcweir ORefCount()56cdf0e10cSrcweir ORefCount() { m_RefCount = 0; } ORefCount(RefCount n)57cdf0e10cSrcweir ORefCount(RefCount n) { m_RefCount = n; } 58cdf0e10cSrcweir virtual ~ORefCount(); 59cdf0e10cSrcweir acquire()60cdf0e10cSrcweir RefCount SAL_CALL acquire() { return (osl_incrementInterlockedCount(&m_RefCount)); }; release()61cdf0e10cSrcweir RefCount SAL_CALL release() { return (osl_decrementInterlockedCount(&m_RefCount)); }; 62cdf0e10cSrcweir operator ++()63cdf0e10cSrcweir RefCount SAL_CALL operator++() { return acquire(); } 64cdf0e10cSrcweir // don't implement the postfix operator, it won't function this way! 65cdf0e10cSrcweir operator --()66cdf0e10cSrcweir RefCount SAL_CALL operator--() { return release(); } 67cdf0e10cSrcweir // don't implement the postfix operator, it won't function this way! 68cdf0e10cSrcweir referenced() const69cdf0e10cSrcweir RefCount SAL_CALL referenced() const 70cdf0e10cSrcweir { return (m_RefCount); } 71cdf0e10cSrcweir 72cdf0e10cSrcweir protected: 73cdf0e10cSrcweir RefCount m_RefCount; 74cdf0e10cSrcweir 75cdf0e10cSrcweir private: 76cdf0e10cSrcweir // disable copy/assignment 77cdf0e10cSrcweir ORefCount(const ORefCount&); 78cdf0e10cSrcweir ORefCount& SAL_CALL operator= (const ORefCount&); 79cdf0e10cSrcweir }; 80cdf0e10cSrcweir 81cdf0e10cSrcweir class OReference : public vos::IReference 82cdf0e10cSrcweir { 83cdf0e10cSrcweir public: 84cdf0e10cSrcweir OReference(); 85cdf0e10cSrcweir virtual ~OReference(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir virtual RefCount SAL_CALL acquire(); 88cdf0e10cSrcweir virtual RefCount SAL_CALL release(); 89cdf0e10cSrcweir referenced() const90cdf0e10cSrcweir virtual RefCount SAL_CALL referenced() const 91cdf0e10cSrcweir { return (m_RefCount.referenced()); } 92cdf0e10cSrcweir 93cdf0e10cSrcweir protected: 94cdf0e10cSrcweir ORefCount m_RefCount; 95cdf0e10cSrcweir 96cdf0e10cSrcweir private: 97cdf0e10cSrcweir // disable copy/assignment 98cdf0e10cSrcweir OReference(const OReference&); 99cdf0e10cSrcweir OReference& SAL_CALL operator= (const OReference&); 100cdf0e10cSrcweir }; 101cdf0e10cSrcweir 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir #endif // _VOS_REFERNCE_HXX_ 105cdf0e10cSrcweir 106