Alternaria
fit cylinders and ellipsoids to fungus
printable.cpp
Go to the documentation of this file.
00001 /*
00002  * This work is licensed under a Creative Commons 
00003  * Attribution-Noncommercial-Share Alike 3.0 United States License.
00004  * 
00005  *    http://creativecommons.org/licenses/by-nc-sa/3.0/us/
00006  * 
00007  * You are free:
00008  * 
00009  *    to Share - to copy, distribute, display, and perform the work
00010  *    to Remix - to make derivative works
00011  * 
00012  * Under the following conditions:
00013  * 
00014  *    Attribution. You must attribute the work in the manner specified by the
00015  *    author or licensor (but not in any way that suggests that they endorse you
00016  *    or your use of the work).
00017  * 
00018  *    Noncommercial. You may not use this work for commercial purposes.
00019  * 
00020  *    Share Alike. If you alter, transform, or build upon this work, you may
00021  *    distribute the resulting work only under the same or similar license to
00022  *    this one.
00023  * 
00024  * For any reuse or distribution, you must make clear to others the license
00025  * terms of this work. The best way to do this is by including this header.
00026  * 
00027  * Any of the above conditions can be waived if you get permission from the
00028  * copyright holder.
00029  * 
00030  * Apart from the remix rights granted under this license, nothing in this
00031  * license impairs or restricts the author's moral rights.
00032  */
00033 
00034 
00046 #include <config.h>
00047 
00048 #include <cstring>
00049 #include <iostream>
00050 #include <sstream>
00051 
00052 #include <jwsc++/base/exception.h>
00053 
00054 #include "printable.h"
00055 
00056 
00057 using std::ostringstream;
00058 using jwscxx::base::IO_error;
00059 using jwscxx::base::Arg_error;
00060 
00061 
00078 const char* Printable::get_member_value
00079 (
00080     const char*   member_name, 
00081     std::istream& in
00082 ) 
00083 throw (Arg_error, IO_error)
00084 {
00085     static char member_buf[256] = {0};
00086 
00087     in.getline(member_buf, 256);
00088     if (in.fail()) 
00089     {
00090         throw IO_error("Could not read member line");
00091     }
00092 
00093     const char* member_ptr = member_buf;
00094 
00095     while (isspace(*member_ptr) && *member_ptr != 0)
00096         member_ptr++;
00097 
00098     if (strncmp(member_ptr, member_name, strlen(member_name)) != 0)
00099     {
00100         ostringstream ost;
00101         ost << "Field name '" << member_name << "' not found in '" 
00102             << member_buf << "'";
00103         throw Arg_error(ost.str());
00104     }
00105 
00106     while (*member_ptr != ':' && *member_ptr != 0)
00107         member_ptr++;
00108 
00109     if (*member_ptr == 0)
00110     {
00111         ostringstream ost;
00112         ost << "Field '" << member_buf << "' improperly formatted";
00113         throw Arg_error(ost.str());
00114     }
00115 
00116     member_ptr++;
00117 
00118     while (isspace(*member_ptr) && *member_ptr != 0)
00119         member_ptr++;
00120 
00121     if (*member_ptr == 0)
00122         return 0;
00123 
00124     return member_ptr;
00125 }
00126 
00127 
00135 const char* Printable::get_next_member_value(const char* member_value) 
00136 {
00137     while (!isspace(*member_value) && *member_value != 0)
00138         member_value++;
00139 
00140     if (*member_value == 0)
00141         return 0;
00142 
00143     while (isspace(*member_value) && *member_value != 0)
00144         member_value++;
00145 
00146     if (*member_value == 0)
00147         return 0;
00148 
00149     return member_value;
00150 }