Sirikata
|
00001 // Copyright (c) 2011 Sirikata Authors. All rights reserved. 00002 // Use of this source code is governed by a BSD-style license that can 00003 // be found in the LICENSE file. 00004 00005 #ifndef _SIRIKATA_LIBCORE_OHDP_DEFS_HPP_ 00006 #define _SIRIKATA_LIBCORE_OHDP_DEFS_HPP_ 00007 00008 #include <sirikata/core/xdp/Defs.hpp> 00009 00010 namespace Sirikata { 00011 namespace OHDP { 00012 00013 typedef Sirikata::XDP::PortID PortID; 00014 00015 class SIRIKATA_EXPORT NodeID { 00016 public: 00017 NodeID(); 00018 NodeID(uint32 rhs); 00019 NodeID(const NodeID& rhs); 00020 explicit NodeID(const String& rhs); 00021 00023 static const NodeID& null(); 00027 static const NodeID& self(); 00029 static const NodeID& any(); 00030 00031 NodeID& operator=(const NodeID& rhs); 00032 NodeID& operator=(uint32 rhs); 00033 00034 operator uint32() const; 00035 00036 bool operator==(const NodeID& rhs) const; 00037 bool operator!=(const NodeID& rhs) const; 00038 bool operator>(const NodeID& rhs) const; 00039 bool operator>=(const NodeID& rhs) const; 00040 bool operator<(const NodeID& rhs) const; 00041 bool operator<=(const NodeID& rhs) const; 00042 00043 String toString() const; 00044 00048 bool matches(const NodeID& rhs) const; 00049 00050 size_t hash() const { return std::tr1::hash<uint32>()(mValue); } 00051 00052 class Hasher { 00053 public: 00054 size_t operator()(const NodeID& p) const { 00055 return p.hash(); 00056 } 00057 }; 00058 00059 private: 00060 uint32 mValue; 00061 }; 00062 00063 SIRIKATA_FUNCTION_EXPORT std::ostream& operator<<(std::ostream& os, const NodeID& rhs); 00064 00066 class SIRIKATA_EXPORT SpaceNodeID : public TotallyOrdered<SpaceNodeID> { 00067 public: 00068 SpaceNodeID(); 00069 SpaceNodeID(const SpaceID& s, const NodeID& n); 00070 // Construct a SpaceNodeID from the given string, using null() if it cannot 00071 // be parsed. 00072 explicit SpaceNodeID(const String& rhs); 00073 00074 const SpaceID& space() const { return mSpace; } 00075 const NodeID& node() const { return mNode; } 00076 00078 static const SpaceNodeID& null(); 00079 00080 bool operator==(const SpaceNodeID& rhs) const; 00081 bool operator<(const SpaceNodeID& rhs) const; 00082 00083 String toString() const; 00084 00085 class SIRIKATA_EXPORT Hasher { 00086 public: 00087 size_t operator()(const SpaceNodeID& p) const; 00088 }; 00089 private: 00090 SpaceID mSpace; 00091 NodeID mNode; 00092 }; 00093 00094 SIRIKATA_FUNCTION_EXPORT std::ostream& operator<<(std::ostream& os, const SpaceNodeID& rhs); 00095 00096 class Endpoint; 00097 00106 class SIRIKATA_EXPORT Endpoint : public Sirikata::XDP::Endpoint<NodeID> { 00107 public: 00108 typedef Sirikata::XDP::Endpoint<NodeID> EndpointBase; 00109 00114 typedef std::tr1::function<void(const Endpoint& src, const Endpoint& dst, MemoryReference)> MessageHandler; 00115 00116 00117 Endpoint(const SpaceID& space, const NodeID& node, const PortID& port) 00118 : EndpointBase(space, node, port) 00119 {} 00120 Endpoint(const SpaceNodeID& spacenode, const PortID& port) 00121 : EndpointBase(spacenode.space(), spacenode.node(), port) 00122 {} 00123 00125 static const Endpoint& null() { 00126 static Endpoint null_ep(SpaceID::null(), NodeID::null(), PortID::null()); 00127 return null_ep; 00128 } 00132 static const Endpoint& any() { 00133 static Endpoint any_ep(SpaceID::any(), NodeID::any(), PortID::any()); 00134 return any_ep; 00135 } 00136 00137 const NodeID& node() const { return EndpointBase::id(); } 00138 00139 private: 00140 Endpoint(); 00141 }; // class Endpoint 00142 00143 typedef Endpoint::MessageHandler MessageHandler; 00144 00145 } // namespace OHDP 00146 } // namespace Sirikata 00147 00148 #endif //_SIRIKATA_LIBCORE_OHDP_DEFS_HPP_