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