Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ippStringBuilder.cpp

Go to the documentation of this file.
00001 // 
00002 // DISCLAIMER: 
00003 //  This software was produced by the National Institute of Standards 
00004 //  and Technology (NIST), an agency of the U.S. government, and by statute is 
00005 //  not subject to copyright in the United States.  Recipients of this 
00006 //  software assume all responsibility associated with its operation,
00007 //  modification,maintenance, and subsequent redistribution. 
00008 //
00009 //  See NIST Administration Manual 4.09.07 b and Appendix I. 
00010 //
00011 #include "stdafx.h"
00012 #include "ippdme/misc/ippStringBuilder.h"
00013 #include "ippdme/ippTag.h"
00014 #include "ippdme/ippTargetVector.h"
00015 #include "ippdme/assert.h"
00016 
00017 ippStringBuilder::ippStringBuilder()
00018 {
00019   init();
00020 }
00021 
00022 void ippStringBuilder::init()
00023 {
00024   _buffer=new char[65535];
00025   _cur = _buffer;
00026   _stack.push_back(0);
00027 }
00028 
00029 ippStringBuilder::ippStringBuilder(
00030  const ippTag& tag,
00031  char const * marker
00032 )
00033 {
00034   init();
00035   int k = sprintf(_cur,"%s %1s ",tag.getTagString().c_str(),marker);
00036   _cur+=k;
00037 }
00038 
00039 ippStringBuilder::ippStringBuilder(
00040  const ippTag& tag
00041 )
00042 {
00043   init();
00044   int k = sprintf(_cur,"%s ",tag.getTagString().c_str());
00045   _cur+=k;
00046 }
00047 
00048 ippStringBuilder::~ippStringBuilder()
00049 {
00050   delete [] _buffer;
00051   _buffer =0;
00052   _cur = 0;
00053 }
00054 
00055 /* !ippStringBuilder::Append
00056  * append text verbatim to the string.
00057  *
00058  */
00059 void ippStringBuilder::Append(const char * text)
00060 {
00061   int k = sprintf(_cur,"%s",text);
00062   _cur+=k;
00063 }
00064 
00065 void ippStringBuilder::StartFunc(const char* func_name)
00066 {
00067   new_argument();
00068   int k = sprintf(_cur,"%s(",func_name);
00069   _cur+=k;
00070   _stack.push_back(0);
00071 }
00072 void ippStringBuilder::StartFunc(ippCommandNameType type)
00073 {
00074   StartFunc(getCommandNameString(type));
00075 }
00076 
00077 void ippStringBuilder::EndFunc()
00078 {
00079   IPP_ASSERT(_stack.size()>0);
00080   Append(")");
00081   _stack.pop_back();
00082 }
00083 
00084 void ippStringBuilder::new_argument()
00085 {
00086   if(_stack.size()==0) return;
00087   if(_stack.back() >0) { 
00088     Append(", ");
00089   }
00090   _stack.back()++;
00091 }
00092 
00093 void ippStringBuilder::AppendParam(double value)
00094 {
00095   new_argument();
00096 
00097   int k = sprintf(_cur,"%.5lG",value); 
00098   char* ptr=_cur;
00099   while (*ptr!=0 && *ptr!='.' && *ptr!='E'){
00100     ptr++;
00101   }
00102   if (*ptr !='.' && *ptr !='E') {
00103     *ptr++='.';
00104     *ptr++=0;
00105   }        
00106   _cur+=strlen(_cur);
00107 
00108 }
00109 
00110  
00111 void ippStringBuilder::AppendParam( ippChangeToolActionType value)
00112 {
00113   new_argument();
00114   int k = sprintf(_cur,"%s",toString(value));
00115   _cur+=k;
00116 }
00117 void ippStringBuilder::AppendParam( ippCoordSysType value)
00118 {
00119   new_argument();
00120   int k = sprintf(_cur,"%s",toString(value));
00121   _cur+=k;
00122 }
00123 void ippStringBuilder::AppendParam( ippMachineClassType value)
00124 {
00125   new_argument();
00126   int k = sprintf(_cur,"%s",toString(value));
00127   _cur+=k;
00128 }
00129 void ippStringBuilder::AppendParam( const ippErrorNameType& value)
00130 {
00131   new_argument();
00132   int k = sprintf(_cur,"%04d",value.asInteger());
00133   _cur+=k;
00134 }
00135 
00136 
00137 void ippStringBuilder::AppendParam(int value)
00138 {
00139   new_argument();
00140   int k = sprintf(_cur,"%d",value);
00141   _cur+=k;
00142 }
00143 void ippStringBuilder::AppendParam(const char* value)
00144 {
00145   new_argument();
00146   int k = sprintf(_cur,"\"%s\"",value);
00147   _cur+=k;
00148 }
00149 
00150 ippStringBuilder& ippStringBuilder::AppendFunc(const char* param_name,double value)
00151 {
00152   StartFunc(param_name);
00153     AppendParam(value);
00154   EndFunc();
00155   return *this;
00156 }
00157 ippStringBuilder& ippStringBuilder::AppendFunc(const char* param_name,int value)
00158 {
00159   StartFunc(param_name);
00160     AppendParam(value);
00161   EndFunc();
00162   return *this;
00163 }
00164 ippStringBuilder& ippStringBuilder::AppendFunc(const char* func_name,const char* value)
00165 {
00166   StartFunc(func_name);
00167     AppendParam(value);
00168   EndFunc();
00169   return *this;
00170 }
00171 
00172 ippStringBuilder& ippStringBuilder::AppendFunc(const char* func_name,double v1,double v2,double v3)
00173 {
00174   StartFunc(func_name);
00175     AppendParam(v1);
00176     AppendParam(v2);
00177     AppendParam(v3);
00178   EndFunc();
00179   return *this;
00180 }
00181 
00182 ippStringBuilder& ippStringBuilder::AppendFunc(const char* func_name,const ippTargetVector& v)
00183 {
00184   return AppendFunc(func_name,v.getI(),v.getJ(),v.getK());
00185 }
00186 
00187 ippStringBuilder& ippStringBuilder::AppendFunc(const char* func_name,const ippErrorNameType& value)
00188 {
00189   StartFunc(func_name);
00190     AppendParam(value);
00191   EndFunc();
00192   return *this;
00193 }
00194 
00195 ippStringBuilder& ippStringBuilder::AppendFunc(const char*func_name,ippMachineClassType value)
00196 {
00197   StartFunc(func_name);
00198     AppendParam(value);
00199   EndFunc();
00200   return *this;
00201 }
00202 
00203 ippStringBuilder& ippStringBuilder::AppendFunc(const char* func_name,ippCoordSysType value)
00204 {
00205   StartFunc(func_name);
00206     AppendParam(value);
00207   EndFunc();
00208   return *this;
00209 }
00210 
00211 ippStringBuilder& ippStringBuilder::AppendFunc(const char* func_name)
00212 {
00213   StartFunc(func_name);
00214   EndFunc();
00215   return *this;
00216 }
00217 
00218 std::string ippStringBuilder::ToString() const
00219 {
00220   IPP_ASSERT(_stack.size()==1);
00221   // add the final 13 /10 characters
00222   int k = sprintf(_cur,"%c%c",13,10);
00223   return _buffer;
00224 }

Generated on Wed Nov 8 00:20:04 2006 for IPPDME by  doxygen 1.4.1