CPPXT-104 - Add exception handling to integer conversions
[shibboleth/cpp-xmltooling.git] / xmltooling / Lockable.h
index 42d4b47..c10c2bf 100644 (file)
@@ -1,23 +1,27 @@
-/*
- *  Copyright 2001-2006 Internet2
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
- * @file Lockable.h
+ * @file xmltooling/Lockable.h
  * 
- * Locking abstraction 
+ * Locking abstraction.
  */
 
 #ifndef __xmltooling_lockable_h__
@@ -30,9 +34,12 @@ namespace xmltooling {
     /**
      * Abstract mixin interface for interfaces that support locking
      */
-    struct XMLTOOL_API Lockable
+    class XMLTOOL_API Lockable
     {
-        virtual ~Lockable() {}
+    protected:
+        Lockable();
+    public:
+        virtual ~Lockable();
         
         /**
          * Lock the associated object for exclusive access.
@@ -60,12 +67,7 @@ namespace xmltooling {
          * @param lockee    pointer to an object to hold, and optionally lock
          * @param lock      true iff object is not yet locked
          */
-        Locker(Lockable* lockee=NULL, bool lock=true) {
-            if (lockee && lock)
-                m_lockee=lockee->lock();
-            else
-                m_lockee=lockee;
-        }
+        Locker(Lockable* lockee=nullptr, bool lock=true);
 
         /**
          * Optionally locks an object and stores it for later release.
@@ -74,23 +76,12 @@ namespace xmltooling {
          * @param lockee    pointer to an object to hold, and optionally lock
          * @param lock      true iff object is not yet locked
          */
-        void assign(Lockable* lockee=NULL, bool lock=true) {
-            if (m_lockee)
-                m_lockee->unlock();
-            m_lockee=NULL;
-            if (lockee && lock)
-                m_lockee=lockee->lock();
-            else
-                m_lockee=lockee;
-        }
+        void assign(Lockable* lockee=nullptr, bool lock=true);
         
         /**
          * Destructor releases lock on held pointer, if any.
          */
-        ~Locker() {
-            if (m_lockee)
-                m_lockee->unlock();
-         }
+        ~Locker();
         
     private:
         Lockable* m_lockee;