javacommons/utils/inc/javauid.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #ifndef JAVAUID_H
       
    18 #define JAVAUID_H
       
    19 
       
    20 #include <string>
       
    21 #include <iostream>
       
    22 #include <ostream>
       
    23 
       
    24 namespace java
       
    25 {
       
    26 namespace util
       
    27 {
       
    28 
       
    29 /**
       
    30  * This class manages application id.
       
    31  * Note: THIS CLASS DOES NOT HAVE VIRTUAL DESTRUCTOR SO DO NOT INHERIT YOUR CLASS
       
    32  *       FROM THIS CLASS!
       
    33  */
       
    34 class Uid
       
    35 {
       
    36 public:
       
    37 
       
    38     Uid() {}
       
    39 
       
    40     Uid(const std::wstring& aStr):mId(aStr) {}
       
    41 
       
    42     ~Uid() {}
       
    43 
       
    44     Uid(const Uid& aUid)
       
    45     {
       
    46         mId = aUid.mId;
       
    47     }
       
    48 
       
    49     Uid& operator= (const Uid& aUid)
       
    50     {
       
    51         mId = aUid.mId;
       
    52         return *this;
       
    53     }
       
    54 
       
    55     bool operator== (const Uid& aUid) const
       
    56     {
       
    57         return (mId == aUid.mId);
       
    58     }
       
    59 
       
    60     bool operator!= (const Uid& aUid) const
       
    61     {
       
    62         return !(mId == aUid.mId);
       
    63     }
       
    64 
       
    65     bool operator< (const Uid& aUid) const
       
    66     {
       
    67         return (mId < aUid.mId);
       
    68     }
       
    69 
       
    70     //bool operator() (const Uid& aUid)
       
    71     //{return (*this < aUid);}
       
    72 
       
    73     const std::wstring& toString() const
       
    74     {
       
    75         return mId;
       
    76     }
       
    77 
       
    78     bool isEmpty() const
       
    79     {
       
    80         return (0 == mId.size());
       
    81     }
       
    82 
       
    83 private:
       
    84 
       
    85     std::wstring mId;
       
    86 
       
    87 };
       
    88 
       
    89 }//end namespace util
       
    90 }//end namespace java
       
    91 
       
    92 inline std::wostream& operator<< (std::wostream& aStream,const java::util::Uid& aUid)
       
    93 {
       
    94     aStream << aUid.toString();
       
    95     return aStream;
       
    96 }
       
    97 
       
    98 inline std::ostream& operator<< (std::ostream& aStream,const java::util::Uid& aUid)
       
    99 {
       
   100     std::wstring tmpWStr(aUid.toString());
       
   101     std::string tmpStr(tmpWStr.begin(),tmpWStr.end());
       
   102     aStream << tmpStr;
       
   103     return aStream;
       
   104 }
       
   105 
       
   106 inline std::wistream& operator>> (std::wistream& aStream,java::util::Uid& aUid)
       
   107 {
       
   108     std::wstring tmpStr;
       
   109     aStream >> tmpStr;
       
   110     java::util::Uid tmpUid(tmpStr);
       
   111     aUid = tmpUid;
       
   112     return aStream;
       
   113 }
       
   114 
       
   115 inline std::istream& operator>> (std::istream& aStream,java::util::Uid& aUid)
       
   116 {
       
   117     std::string tmpStr;
       
   118     aStream >> tmpStr;
       
   119     std::wstring tmpWStr(tmpStr.begin(),tmpStr.end());
       
   120     java::util::Uid tmpUid(tmpWStr);
       
   121     aUid = tmpUid;
       
   122     return aStream;
       
   123 }
       
   124 
       
   125 #endif // JAVAUID_H
       
   126