src/foundation/ZUtil_Tuple.h

00001 /*  @(#) $Id: ZUtil_Tuple.h,v 1.12 2006/10/13 20:00:29 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 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 __ZUtil_Tuple__
00026 #define __ZUtil_Tuple__ 1
00027 #include "zconfig.h"
00028 
00029 #include <string>
00030 #include <vector>
00031 
00032 class ZStrimR;
00033 class ZStrimU;
00034 class ZStrimW;
00035 
00036 class ZTuple;
00037 class ZTupleValue;
00038 
00039 namespace ZUtil_Tuple {
00040 
00041 // =================================================================================================
00042 #pragma mark -
00043 #pragma mark * ZUtil_Tuple::Options
00044 
00045 struct Options
00046         {
00047         Options(bool iDoIndentation = false);
00048 
00049         std::string fEOLString;
00050         std::string fIndentString;
00051 
00052         int fRawChunkSize;
00053         std::string fRawByteSeparator;
00054         bool fRawAsASCII;
00055 
00056         bool fBreakStrings;
00057         int fStringLineLength;
00058 
00059         bool fIDsHaveDecimalVersionComment;
00060 
00061         bool fTimesHaveUserLegibleComment;
00062 
00063         bool DoIndentation() const { return !fIndentString.empty(); }
00064         };
00065 
00066 // =================================================================================================
00067 #pragma mark -
00068 #pragma mark * ZUtil_Tuple::Format
00069 
00070 struct Format
00071         {
00072         Format(const ZTupleValue& iTupleValue, int iInitialIndent, const Options& iOptions);
00073 
00074         const ZTupleValue& fTupleValue;
00075         int fInitialIndent;
00076         const Options& fOptions;
00077         };
00078 
00079 // =================================================================================================
00080 #pragma mark -
00081 #pragma mark * ZUtil_Tuple, writing and parsing pieces
00082 
00083 void sWrite_PropName(const ZStrimW& iStrimW, const string& iPropName);
00084 
00085 bool sRead_Identifier(const ZStrimU& iStrimU, string* oStringLC, string* oStringExact);
00086 
00087 // =================================================================================================
00088 #pragma mark -
00089 #pragma mark * ZUtil_Tuple, TupleValue
00090 
00091 void sToStrim(const ZStrimW& iStrimW, const ZTupleValue& iTupleValue);
00092 
00093 void sToStrim(const ZStrimW& iStrimW, const ZTupleValue& iTupleValue,
00094         size_t iInitialIndent, const Options& iOptions);
00095 
00096 std::string sAsString(const ZTupleValue& iTupleValue);
00097 
00098 bool sFromStrim(const ZStrimU& iStrimU, ZTupleValue& oTupleValue);
00099 
00100 bool sFromString(const std::string& iString, ZTupleValue& oTupleValue);
00101 
00102 // =================================================================================================
00103 #pragma mark -
00104 #pragma mark * ZUtil_Tuple, vector<ZTupleValue>
00105 
00106 void sToStrim(const ZStrimW& iStrimW, const std::vector<ZTupleValue>& iVector);
00107 
00108 void sToStrim(const ZStrimW& iStrimW, const std::vector<ZTupleValue>& iVector,
00109         size_t iInitialIndent, const Options& iOptions);
00110 
00111 std::string sAsString(const std::vector<ZTupleValue>& iVector);
00112 
00113 bool sFromStrim(const ZStrimU& iStrimU, std::vector<ZTupleValue>& oVector);
00114 
00115 bool sFromString(const std::string& iString, std::vector<ZTupleValue>& oVector);
00116 
00117 // =================================================================================================
00118 #pragma mark -
00119 #pragma mark * ZUtil_Tuple, ZTuple
00120 
00121 void sToStrim(const ZStrimW& iStrimW, const ZTuple& iTuple);
00122 
00123 void sToStrim(const ZStrimW& iStrimW, const ZTuple& iTuple,
00124         size_t iInitialIndent, const Options& iOptions);
00125 
00126 std::string sAsString(const ZTuple& iTuple);
00127 
00128 std::string sAsString(const ZTuple& iTuple,
00129         size_t iInitialIndent, const Options& iOptions);
00130 
00131 bool sFromStrim(const ZStrimU& iStrimU, ZTuple& oTuple);
00132 
00133 bool sFromString(const std::string& iString, ZTuple& oTuple);
00134 
00135 }  // namespace ZUtil_Tuple
00136 
00137 // =================================================================================================
00138 #pragma mark -
00139 #pragma mark * operator<< overloads
00140 
00141 const ZStrimW& operator<<(const ZStrimW& s, const ZTupleValue& iTupleValue);
00142 
00143 const ZStrimW& operator<<(const ZStrimW& s, const ZUtil_Tuple::Format& iFormat);
00144 
00145 #endif // __ZUtil_Tuple__

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