MOOCHO (Single Doxygen Collection) Version of the Day
StandardCompositionRelationshipsPack.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef STANDARD_COMPOSITION_RELATIONSHIPS_PACK_H
00030 #define STANDARD_COMPOSITION_RELATIONSHIPS_PACK_H
00031 
00032 #include "Moocho_ConfigDefs.hpp"
00033 #include "Teuchos_TestForException.hpp"
00034 
00035 namespace StandardCompositionRelationshipsPack {
00036 
00043 
00045 class NoRefSet : public std::logic_error
00046 {public: NoRefSet(const std::string& what_arg) : std::logic_error(what_arg) {}};
00047 
00048 // Throw a NoRefSet exception
00049 inline void ThrowNoRefSet(const char func_name[], const char name[])
00050 {
00051   TEST_FOR_EXCEPTION(
00052     true,NoRefSet
00053     ,func_name << ": The reference for \'" << name << "\' has not been set yet"
00054     );
00055 }
00056 
00058 template<class ContainedClass>
00059 inline void assert_role_name_set(const ContainedClass* role_name_, const char func_name[]
00060   , const char name[])
00061 {
00062   if(!role_name_) ThrowNoRefSet(func_name, name);
00063 }
00064 
00066 template<class ContainedClass>
00067 inline void set_role_name(ContainedClass*& role_name_, bool& owns_role_name_, const char name[]
00068   , ContainedClass* role_name, bool owns_role_name)
00069 {
00070   if(owns_role_name_ && role_name_ != role_name) delete role_name_;
00071   role_name_ = role_name; owns_role_name_ = owns_role_name;
00072 }
00073 
00075 template<class ContainedClass>
00076 inline ContainedClass* get_role_name(ContainedClass* role_name_, bool owns_role_name_
00077   , const char name[])
00078 {
00079   return role_name_;
00080 }
00081 
00083 template<class ContainedClass>
00084 inline void set_owns_role_name(ContainedClass*& role_name_, bool& owns_role_name_
00085   , const char name[], bool owns_role_name)
00086 {
00087   assert_role_name_set(role_name_, "set_owns_role_name()", name);
00088   owns_role_name_ = owns_role_name;
00089 }
00090 
00092 template<class ContainedClass>
00093 inline bool owns_role_name(ContainedClass* role_name_, bool owns_role_name_, const char name[])
00094 {
00095   assert_role_name_set(role_name_, "owns_role_name()", name);
00096   return owns_role_name_;
00097 }
00098 
00100 template<class ContainedClass>
00101 inline ContainedClass& role_name(ContainedClass* role_name_, bool owns_role_name_, const char name[])
00102 {
00103   assert_role_name_set(role_name_, "role_name()", name);
00104   return *role_name_;
00105 }
00106 
00108 template<class ContainedClass>
00109 inline const ContainedClass& role_name(const ContainedClass* role_name_, bool owns_role_name_, const char name[])
00110 {
00111   assert_role_name_set(role_name_, "role_name()", name);
00112   return *role_name_;
00113 }
00114 
00116 template<class ContainedClass>
00117 inline const ContainedClass& const_role_name(const ContainedClass* role_name_, bool owns_role_name_, const char name[])
00118 {
00119   assert_role_name_set(role_name_, "role_name()", name);
00120   return *role_name_;
00121 }
00122 
00123 
00125 template<class ContainedClass>
00126 inline void destory_container_obj(ContainedClass* role_name_, bool owns_role_name_)
00127 {
00128   if(owns_role_name_) delete role_name_;
00129 }
00130 
00132 
00133 } // end namespace StandardCompositionRelationshipsPack
00134 
00135 #endif // STANDARD_COMPOSITION_RELATIONSHIPS_PACK_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines