src/foundation/ZTrail.h

00001 /*  @(#) $Id: ZTrail.h,v 1.7 2007/01/10 01:15:36 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2004 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZTrail__
00026 #define __ZTrail__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZUnicode.h"
00030 
00031 #include <string>
00032 #include <vector>
00033 
00034 #include "ZCompat_operator_bool.h"
00035 
00036 // =================================================================================================
00037 #pragma mark -
00038 #pragma mark * ZTrail
00039 
00040 class ZTrail
00041         {
00042     ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZTrail, operator_bool_generator_type, operator_bool_type);
00043 public:
00044         ZTrail();
00045         ZTrail(bool iValid);
00046 
00047         ZTrail(const ZTrail& iTrail);
00048 
00049         ZTrail(const std::string& iPOSIXTrail);
00050         ZTrail(const char* iPOSIXTrail);
00051         ZTrail(const char* iPOSIXTrail, size_t iSize);
00052 
00053         ZTrail(const std::string& iSeparator, const std::string& iIgnore, const std::string& iBounce, const std::string& iTrail);
00054 
00055         template <class I>
00056         ZTrail(const I& iBegin, const I& iEnd)
00057         :       fComps(iBegin, iEnd),
00058                 fValid(true)
00059                 {}
00060 
00061         ~ZTrail();
00062 
00063         operator operator_bool_type() const;
00064 
00065         ZTrail& operator=(const ZTrail& iTrail);
00066 
00067         ZTrail operator+(const ZTrail& iTrail) const;
00068         ZTrail& operator+=(const ZTrail& iTrail);
00069 
00070         template <class I>
00071         void AppendTrail(const I& iBegin, const I& iEnd)
00072                 { fComps.insert(fComps.end(), iBegin, iEnd); }
00073         void AppendTrail(const ZTrail& iTrail);
00074         void AppendComp(const std::string& iComp);
00075         void AppendBounce();
00076         void AppendBounces(size_t iCount);
00077 
00078         template <class I>
00079         void PrependTrail(const I& iBegin, const I& iEnd)
00080                 { fComps.insert(fComps.begin(), iBegin, iEnd);}
00081         void PrependTrail(const ZTrail& iTrail);
00082         void PrependComp(const std::string& iComp);
00083         void PrependBounce();
00084         void PrependBounces(size_t iCount);
00085 
00086         std::string AsString() const;
00087         std::string AsString(const std::string& iSeparator, const std::string& iBounce) const;
00088 
00089         ZTrail Branch() const;
00090         std::string Leaf() const;
00091 
00092         size_t Count() const;
00093         std::string At(size_t iIndex) const;
00094         ZTrail SubTrail(size_t iBegin, size_t iEnd) const;
00095         ZTrail SubTrail(size_t iBegin) const;
00096 
00097         ZTrail Normalized() const;
00098         ZTrail& Normalize();
00099         bool IsNormalized() const;
00100 
00101         const std::vector<std::string>& GetComps() const
00102                 { return fComps; }
00103 
00104         static ZTrail sTrailFromTo(const std::vector<std::string>& iSource,
00105                 const std::vector<std::string>& iDest);
00106 
00107         static void sParseStringAndAppend(const UTF8* iSeparator,
00108                                                         const char* iIgnore,
00109                                                         const char* iBounce,
00110                                                         const char* iPath, size_t iPathSize,
00111                                                         std::vector<std::string>& ioComps);
00112 
00113         static void sParseStringAndAppend(const UTF16* iSeparator,
00114                                                         const UTF16* iIgnore,
00115                                                         const UTF16* iBounce,
00116                                                         const UTF16* iPath, size_t iPathSize,
00117                                                         std::vector<string16>& ioComps);
00118 
00119         static size_t sNormalize_ReturnLeadingBounces(const std::vector<std::string>& iComps,
00120                 std::vector<std::string>& oComps);
00121 
00122 private:
00123         std::vector<std::string> fComps;
00124         bool fValid;
00125         };
00126 
00127 #endif // __ZTrail__

Generated on Thu Jul 26 11:21:51 2007 for ZooLib by  doxygen 1.4.7