[Mobies-commit] [commit] r4318 - UDM/trunk/include

ksmyth at redhat3.isis.vanderbilt.edu ksmyth at redhat3.isis.vanderbilt.edu
Wed Sep 24 09:50:31 CDT 2014


Author: ksmyth
Date: Wed Sep 24 09:50:31 2014
New Revision: 4318

Log:
Operator -> and * for fewer casts

Modified:
   UDM/trunk/include/UdmBase.h

Modified: UDM/trunk/include/UdmBase.h
==============================================================================
--- UDM/trunk/include/UdmBase.h	Wed Sep 17 12:36:30 2014	(r4317)
+++ UDM/trunk/include/UdmBase.h	Wed Sep 24 09:50:31 2014	(r4318)
@@ -1926,6 +1926,29 @@
 
 
 	};
+
+	
+	template<class CLASS>
+	struct AttrPointer
+	{
+		CLASS parent;
+		AttrPointer(CLASS parent)
+#ifdef UDM_RVALUE
+			: parent(std::move(parent)) { }
+#else
+			: parent(parent) { }
+#endif
+		CLASS *operator*()
+		{
+			return &parent;
+		}
+
+		CLASS *operator->()
+		{
+			return &parent;
+		}
+	};
+	
 // --------------------------- CrossAssocAttr
 	template<class CLASS, class Pred = less<CLASS> >
 	class CrossAssocAttr
@@ -2054,6 +2077,17 @@
 			// FIXME: (CLASS) a is destructed then returned by reference. return *this instead
 			return operator =( (CLASS) a );
 		}
+
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
+
 	};
 
 
@@ -2098,6 +2132,17 @@
 			// FIXME: (CLASS) a is destructed then returned by reference. return *this instead
 			return operator =( (CLASS) a );
 		}
+
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
+
 	};
 
 // --------------------------- CrossAssocEndAttr
@@ -2122,6 +2167,17 @@
 			// FIXME: (CLASS) a is destructed then returned by reference. return *this instead
 			return operator =( (CLASS) a );
 		}
+
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
+
 	};
 
 
@@ -2166,6 +2222,15 @@
 			return operator =( (CLASS) a );
 		}
 
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
 	};
 
 // --------------------------- AClassCrossPointerAttr
@@ -2192,6 +2257,16 @@
 			return operator =( (CLASS) a );
 		}
 
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
+
 	};
 // --------------------------- AClassPointerAttr
 
@@ -2235,6 +2310,16 @@
 			return operator =( (CLASS) a );
 		}
 
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
+
 		CLASS SetLink(TARGETCLASS peer, Object parent, 
 			const ::Uml::Class &meta = CLASS::meta,
 			const ::Uml::CompositionChildRole &role = NULLCHILDROLE);
@@ -2496,6 +2581,16 @@
 		{
 			return operator =( (CLASS) a);
 		}
+
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
 	};
 
 // --------------------------- ParentAttr
@@ -2532,6 +2627,16 @@
 			// FIXME: (CLASS) a is destructed then returned by reference. return *this instead
 			return operator =( (CLASS) a );
 		}
+
+		AttrPointer<CLASS> operator->() const 
+		{
+			return AttrPointer<CLASS>(static_cast<CLASS>(*this));
+		}
+
+		CLASS operator*() const
+		{
+			return static_cast<CLASS>(*this);
+		}
 	};
 // -----------------------------Typed set<> container
 


More information about the Mobies-commit mailing list