|
Isis 3.0 Application Source Code Reference |
Home |
00001 #ifndef Commentor_h 00002 #define Commentor_h 00003 /** 00004 * @file 00005 * $Revision: 4943 $ 00006 * $Date: 2013-01-04 11:02:32 -0700 (Fri, 04 Jan 2013) $ 00007 * 00008 * Unless noted otherwise, the portions of Isis written by the USGS are 00009 * public domain. See individual third-party library and package descriptions 00010 * for intellectual property information, user agreements, and related 00011 * information. 00012 * 00013 * Although Isis has been used by the USGS, no warranty, expressed or 00014 * implied, is made by the USGS as to the accuracy and functioning of such 00015 * software and related material nor shall the fact of distribution 00016 * constitute any such warranty, and no responsibility is assumed by the 00017 * USGS in connection therewith. 00018 * 00019 * For additional information, launch 00020 * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html 00021 * in a browser or see the Privacy & Disclaimers page on the Isis website, 00022 * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on 00023 * http://www.usgs.gov/privacy.html. 00024 * 00025 * $Id: Commentor.h 4943 2013-01-04 18:02:32Z janderson $ 00026 */ 00027 #include <string> 00028 #include "TextFile.h" 00029 00030 namespace Isis { 00031 00032 /** 00033 * @brief Generic container for Kernel comments 00034 * 00035 * This class provides an accumulator for the comments that are generated for a 00036 * SPICE kernel. It accepts the comments from a file if provided by the caller 00037 * or, otherwise they are generated using the default comment for a given SPICE 00038 * kernel type. Additionally, an operator()(K &source) segment method is 00039 * provided to collect the comments generated for each segment in a list. This 00040 * is typically the list that is to be written to an eventual SPICE kernel file. 00041 * 00042 * @author 2011-04-01 Kris Becker 00043 * @internal 00044 * @history 2011-04-11 Kris Becker Completed documentation 00045 */ 00046 template <class K> 00047 class Commentor { 00048 public: 00049 /** Constructor w/initialization */ 00050 Commentor() { init(); } 00051 /** Constructor w/caller provided file containing comments */ 00052 Commentor(const QString &comfile) { 00053 init(); 00054 if ( !comfile.isEmpty() ) { 00055 loadCommentFile(comfile); 00056 } 00057 } 00058 00059 /** Destructor */ 00060 virtual ~Commentor() { } 00061 00062 /** Returns full size of current comments internalized */ 00063 int size() const { return (_comComment.size() + _comSetComments.size()); } 00064 00065 /** 00066 * @brief operator() method to collect comments from each segment 00067 * 00068 * This operator method is provided for use in the SpiceKernel class usage 00069 * whereby each segment is called and the comments are retrieved from each 00070 * segment when called. 00071 * 00072 * @param K Segment where specific comments are retreived 00073 */ 00074 void operator()(const K &source) { 00075 _comSetComments.append(source.getComment()); 00076 return; 00077 } 00078 00079 /** 00080 * @brief Loads general comments from a given file 00081 * 00082 * @internal 00083 * @history Debbie A. Cook - Added spkwriter signature keyword to user's 00084 * comment 00085 */ 00086 void loadCommentFile(const QString &comFile) { 00087 _comComment = readCommentFile(comFile); 00088 // The following line was added to ensure that a 00089 // user's entered comment file includes the 00090 // keyword indicating an spkwriter-created kernel. 00091 _comComment += " (ID:USGS_SPK_ABCORR=NONE)\n"; 00092 _comFile = comFile; 00093 return; 00094 } 00095 00096 /** Allows user to set comment header string */ 00097 void setCommentHeader(const QString &comment) { 00098 _comComment = comment; 00099 return; 00100 } 00101 00102 /** Returns the current contents of the collected comments */ 00103 QString Comments() const { 00104 return (_comComment + _comSetComments); 00105 } 00106 00107 /** Clear out all comments collected for starting over */ 00108 void Clear() { 00109 _comSetComments.clear(); 00110 return; 00111 } 00112 00113 private: 00114 QString _comFile; 00115 QString _comComment; 00116 QString _comSetComments; 00117 00118 /** 00119 * @brief Read comments from a file 00120 * 00121 * This method reads a text file containing comments that will be written 00122 * to the SPICE kernel written. 00123 * 00124 * @return QString Returns contents of of comment file 00125 */ 00126 QString readCommentFile(const QString comfile) { 00127 TextFile t(comfile); 00128 QString comment; 00129 QString cline; 00130 while ( t.GetLine(cline, false) ) { 00131 cline.push_back('\n'); 00132 comment += cline; 00133 } 00134 return (comment); 00135 } 00136 00137 /** Initialize setting all content to empty strings */ 00138 void init() { 00139 _comFile = _comComment = _comSetComments = ""; 00140 } 00141 }; 00142 00143 }; // namespace Isis 00144 #endif 00145 00146