EndpointID.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2005 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _ENDPOINT_ID_H_
00039 #define _ENDPOINT_ID_H_
00040 
00041 #include <string>
00042 #include <oasys/serialize/Serialize.h>
00043 #include <oasys/serialize/SerializableVector.h>
00044 
00045 struct dtn_endpoint_id_t;
00046 
00047 namespace dtn {
00048 
00049 class EndpointID;
00050 class EndpointIDPattern;
00051 class Scheme;
00052 
00053 class EndpointID : public oasys::SerializableObject {
00054 public:
00058     EndpointID() : scheme_(NULL), valid_(false), is_pattern_(false) {}
00059 
00063     EndpointID(const oasys::Builder&)
00064         : scheme_(NULL), valid_(false), is_pattern_(false) {}
00065 
00069     EndpointID(const std::string& str)
00070         : str_(str), scheme_(NULL), valid_(false), is_pattern_(false)
00071     {
00072         parse();
00073     }
00074 
00078     EndpointID(const EndpointID& other)
00079         : SerializableObject(other)
00080     {
00081         if (&other != this)
00082             assign(other);
00083     }
00084 
00088     virtual ~EndpointID() {}
00089 
00093     bool assign(const EndpointID& other)
00094     {
00095         str_         = other.str_;
00096         scheme_str_  = other.scheme_str_;
00097         ssp_         = other.ssp_;
00098         scheme_      = other.scheme_;
00099         valid_       = other.valid_;
00100         is_pattern_  = other.is_pattern_;
00101         return true;
00102     }
00103         
00108     bool assign(const std::string& str)
00109     {
00110         str_.assign(str);
00111         return parse();
00112     }
00113 
00118     bool assign(const std::string& scheme, const std::string& ssp)
00119     {
00120         str_ = scheme + ":" + ssp;
00121         return parse();
00122     }
00123 
00127     bool equals(const EndpointID& other) const
00128     {
00129         return str_ == other.str_;
00130     }
00131 
00135     bool operator==(const EndpointID& other) const
00136     {
00137         return str_ == other.str_;
00138     }
00139     
00143     bool operator!=(const EndpointID& other) const
00144     {
00145         return str_ != other.str_;
00146     }
00147 
00153     bool assign(const dtn_endpoint_id_t* eid);
00154 
00162     bool append_service_tag(const char* tag);
00163 
00168     void copyto(dtn_endpoint_id_t* eid) const;
00169 
00173     bool known_scheme() const
00174     {
00175         return (scheme_ != NULL);
00176     }
00177 
00182     static const EndpointID NULL_EID() { return EndpointID("dtn:none"); }
00183     
00189     static const EndpointID WILDCARD_EID() { return EndpointID("*:*"); }
00190     
00194     virtual void serialize(oasys::SerializeAction* a);
00195     
00199     const std::string& str()        const { return str_; }
00200     const std::string& scheme_str() const { return scheme_str_; }
00201     const std::string& ssp()        const { return ssp_; }
00202     Scheme*            scheme()     const { return scheme_; }
00203     bool               valid()      const { return valid_; }
00204     bool               is_pattern() const { return is_pattern_; }
00205     const char*        c_str()      const { return str_.c_str(); } 
00206     const char*        data()       const { return str_.data(); }
00207     size_t             length()     const { return str_.length(); }
00209 
00210 protected:
00216     bool parse();
00217 
00218     std::string str_;           /* the whole string  */
00219     std::string scheme_str_;    /* the scheme string  */
00220     std::string ssp_;           /* the scheme-specific part */
00221     Scheme* scheme_;            /* the scheme class (if known) */
00222     bool valid_;                /* true iff the endpoint id is valid */
00223     bool is_pattern_;           /* true iff this is an EndpointIDPattern */
00224 };
00225 
00231 class EndpointIDPattern : public EndpointID {
00232 public:
00236     EndpointIDPattern() : EndpointID()
00237     {
00238         is_pattern_ = true;
00239     }
00240 
00244     EndpointIDPattern(const std::string& str) : EndpointID()
00245     {
00246         is_pattern_ = true;
00247         assign(str);
00248     }
00249 
00253     EndpointIDPattern(const EndpointIDPattern& other)
00254          : EndpointID(other)
00255     {
00256         is_pattern_ = true;
00257         assign(other);
00258     }
00259 
00264     EndpointIDPattern(const EndpointID& other)
00265     {
00266         is_pattern_ = true;
00267         assign(other);
00268     }
00269 
00274     bool match(const EndpointID& eid) const;
00275    
00276 };
00277 
00281 class EndpointIDVector : public oasys::SerializableVector<EndpointID> {};
00282 
00283 } // namespace dtn
00284 
00285 #endif /* _ENDPOINT_ID_H_ */

Generated on Fri Dec 22 14:47:58 2006 for DTN Reference Implementation by  doxygen 1.5.1