UTPathNode.h

Go to the documentation of this file.
00001 //==================================================================================================
00002 // Copyright (C) 2010  Brian Tietz    sdbtietz at yahoo dot com
00003 //
00004 // This program is free software; you can redistribute it and/or modify it under the terms of the
00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the
00006 // License.
00007 //
00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010 // General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License along with this program; if
00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00014 // 02110-1301, USA.
00015 //
00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com)
00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that
00018 // license as applied to the UT library in exchange for either substantial contributions to the
00019 // development of the UT library or other forms of compensation.  Any such waiver must be
00020 // established in writing between the copyright holder and the commercial entity obtaining such a
00021 // waiver.
00022 //==================================================================================================
00023 
00024 
00025 #ifndef _UT_PATH_NODE_H_
00026 #define _UT_PATH_NODE_H_
00027 
00028 
00029 //==================================================================================================
00030 //=== Project headers
00031 //==================================================================================================
00032 #include "UT.h"
00033 
00034 
00035 //==================================================================================================
00036 //=== Types and constants
00037 //==================================================================================================
00038 
00039 // \cond DOXYGEN_DOCUMENT_NEVER
00040 
00041 enum path_node_result_t
00042 {
00043     ePNR_bad_path       = -1,
00044     ePNR_no_more_nodes  = 0,
00045     ePNR_success        = 1
00046 };
00047 
00048 
00049 //==================================================================================================
00050 class PathNode_t
00051 //==================================================================================================
00052 // Class to facilitate easy traversal of file paths.  It is used internally by the implementation of
00053 // the Path_t class.
00054 {
00055     //----------------------------------------------------------------------------------------------
00056     public:
00057     //----------------------------------------------------------------------------------------------
00058     path_node_result_t      Init(const utf8* text);
00059                                 // Initializes the path node to point to and record the length of
00060                                 // the first node in the specified path.  If the operation is
00061                                 // successful, ePNR_success is returned.  If first path node is not
00062                                 // valid, ePNR_bad_path is returned.  If the text specifies an empty
00063                                 // path, ePNR_no_more_nodes is returned.
00064 
00065     path_node_result_t      Next();
00066                                 // Increments this path node to point to and record the length of
00067                                 // the next node in the specified path.  If the operation is
00068                                 // successful, ePNR_success is returned.  If next path node is not
00069                                 // valid, ePNR_bad_path is returned.  If there are no more nodes in
00070                                 // the path originally passed to Init in the text parameter,
00071                                 // ePNR_no_more_nodes is returned.
00072 
00073     inline const utf8*      UTF8() const;
00074                                 // Returns a pointer to the beginning of the text in the current
00075                                 // path node.  Note that the path node is not null-terminated, and
00076                                 // only the length indicated by the Length function is actually a
00077                                 // part of the current path node.
00078 
00079     inline stringliteral*   ConstChars() const;
00080                                 // Returns a pointer to the beginning of the text in the current
00081                                 // path node.  Note that the path node is not null-terminated, and
00082                                 // only the length indicated by the Length function is actually a
00083                                 // part of the current path node.
00084 
00085     inline int              Length() const;
00086                                 // Returns the length of the current path node.
00087 
00088     //----------------------------------------------------------------------------------------------
00089     private:
00090     //----------------------------------------------------------------------------------------------
00091     static int              CountNodeBytes(const utf8* text);
00092                                 // Returns the number of bytes in this path node, -1 if an invalid
00093                                 // character was found.  An invalid character is one which is not
00094                                 // allowed in a file name, excluding path delimiters.
00095 
00096     //----------------------------------------------------------------------------------------------
00097     private:
00098     //----------------------------------------------------------------------------------------------
00099     const utf8*             m_text;
00100     const utf8*             m_text_base;
00101     int                     m_node_length;
00102 };
00103 
00104 
00105 
00106 
00107 //==================================================================================================
00108 //==================================================================================================
00109 //===
00110 //=== Inline function implementations
00111 //===
00112 //==================================================================================================
00113 //==================================================================================================
00114 inline const utf8*
00115 PathNode_t::UTF8() const
00116 {
00117     return m_text;
00118 }
00119 
00120 
00121 inline stringliteral*
00122 PathNode_t::ConstChars() const
00123 {
00124     return reinterpret_cast<stringliteral*>(m_text);
00125 }
00126 
00127 
00128 inline int
00129 PathNode_t::Length() const
00130 {
00131     return m_node_length;
00132 }
00133 
00134 
00135 // \endcond
00136 #endif // _UT_PATH_NODE_H_

Generated on Tue Dec 14 22:35:05 2010 for UT library by  doxygen 1.6.1