TBConstants.h

Go to the documentation of this file.
00001 //# TBConstants.h: Constants, defaults, and common functions for the browser.
00002 //# Copyright (C) 2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef CONSTANTS_H_
00028 #define CONSTANTS_H_
00029 
00030 #include <sstream>
00031 #include <vector>
00032 #include <map>
00033 
00034 #include <QFrame>
00035 
00036 #include <casa/BasicSL/String.h>
00037 #include <casa/Utilities/DataType.h>
00038 #include <casa/Containers/Record.h>
00039 
00040 #include <xercesc/util/PlatformUtils.hpp>
00041 #include <xercesc/util/XMLString.hpp>
00042 
00043 /*
00044 #ifdef AIPS_HAS_QWT
00045 #include <qwt_plot_curve.h>
00046 #include <qwt_symbol.h>
00047 #endif
00048 */
00049 #include <graphics/GenericPlotter/PlotFactory.h>
00050 
00051 using namespace xercesc;
00052 
00053 namespace casa {
00054 
00055 //# Forward Declarations
00056 class TBTableTabs;
00057 
00058  namespace tb {
00059     // Enum listing the possible types of comparisons that can be made in, for
00060     // example, a filter rule.
00061     enum Comparator {
00062         EQUALS, CONTAINS, BETWEEN, CONTAINSBT, LESSTHAN, CONTAINSLT, GREATERTHAN,
00063         CONTAINSGT
00064     };
00065 
00066     // Enum listing the format for boolean values: "true/false", "t/f", "1/0", etc.
00067     enum BooleanFormat {
00068         DEFAULT, TRUEFALSE, TF, B10
00069     };
00070 
00071     // Enum to indicate the different driver types.
00072     enum Driver {
00073         DIRECT//, XML
00074     };
00075 
00076     // Enum to indicate the different parsers available for XML drivers.
00077     enum Parser {
00078         HOME, XERCES_DOM, XERCES_SAX
00079     };
00080  }
00081 
00082 
00083 // <summary>
00084 // Convenience class for a String/bool tuple.
00085 // <summary>
00086 //
00087 // <synopsis>
00088 // Result is nothing more than a String/bool pair.  Semantically, it can be
00089 // used to return the result of an operation: the String is the value and the
00090 // bool indicates whether that value is valid or the operation was successful.
00091 // </synopsis>
00092 
00093 class Result {
00094 public:
00095     // Construct a Result with the given values.
00096     Result(String r= "", bool v = true): result(r), valid(v) { }
00097 
00098     ~Result() { }
00099 
00100     // Result string.
00101     String result;
00102     
00103     // Result bool.
00104     bool valid;
00105 };
00106 
00107 
00108 // <summary>
00109 // Results of a row locate on at least one table.
00110 // </summary>
00111 //
00112 // <synopsis>
00113 // A TBLocatedRows basically consists of a map from TBTableTabs to vectors of
00114 // ints that represent row numbers.
00115 // </synopsis>
00116 
00117 class TBLocatedRows {
00118 public:
00119     // Default Constructor.
00120     TBLocatedRows();
00121     
00122     ~TBLocatedRows();
00123     
00124     // Returns a list of all the tables in this TBLocatedRows.
00125     std::vector<TBTableTabs*> tables();
00126     
00127     // Associates the given list of row numbers with the given TBTableTabs.
00128     void put(TBTableTabs* tt, std::vector<int>* r);
00129     
00130     
00131     // Results.
00132     std::map<TBTableTabs*, std::vector<int>*> results;
00133 };
00134 
00135 
00136 // <summary>
00137 // Constants, defaults, and commonly-used functions for the table browser.
00138 // <summary>
00139 //
00140 // <synopsis>
00141 // TBConstants contains definitions that may be common or useful to multiple
00142 // classes.
00143 // </synopsis>
00144 
00145 class TBConstants {
00146 public:
00147     /* Debugging Constants/Defaults */
00148     
00149     // The current debug level.
00150     static int debugThreshold;
00151     
00152     // Debug levels.
00153     // <group>
00154     static const int DEBUG_OFF;
00155     static const int DEBUG_LOW;
00156     static const int DEBUG_MED;
00157     static const int DEBUG_HIGH;
00158     // </group>
00159 
00160     // Print the given message to standard out with the given indentation level,
00161     // IF the message's level is at or below the current debugThreshold.
00162     static void dprint(int level, String message, int indentLevel = 0);
00163 
00164     
00165     /* Browsing Constants/Defaults */
00166 
00167     // The default number of rows to load from the table at a time.
00168     static const unsigned int DEFAULT_SELECT_NUM;
00169 
00170     // The default number of rows to load at a time while exporting.
00171     static const unsigned int DEFAULT_EXPORT_NUM;
00172 
00173     // The maximum number of rows to load from the table at a time.
00174     static const unsigned int MAX_SELECT_NUM;
00175 
00176     // The maximum number of actions to keep in action lists.
00177     static const unsigned int MAX_ACTION_BUFFER;
00178 
00179     // The default row interval for plotting.
00180     static const unsigned int DEFAULT_ROW_INTERVAL;
00181 
00182     // Kinds of queries that can be sent to the table through the TBXMLDriver.
00183     // <group>
00184     static const String QUERY_QUERY;
00185     static const String QUERY_ARRAY;
00186     static const String QUERY_UPDATE;
00187     static const String QUERY_FULL;
00188     // </group>
00189 
00190     // Returns the display value of the given Comparator.
00191     static String compToString(tb::Comparator c);
00192 
00193     // Returns the Comparator corresponding to the given display value.
00194     static tb::Comparator stringToComp(String str);
00195 
00196     // Returns the display value of the given BooleanFormat.
00197     static String bFormToString(tb::BooleanFormat bf);
00198 
00199     // Returns the BooleanFormat corresponding to the given display value.
00200     static tb::BooleanFormat stringToBForm(String str);
00201 
00202     // Constants used for an array slicer.  See TBSlicer.
00203     // <group>
00204     static const int SLICER_ROW_AXIS;
00205     static const int SLICER_COL_AXIS;
00206     // </group>
00207     
00208     // Number of rows in an embedded record widget to show by default.
00209     static const unsigned int DEFAULT_RECORD_VISIBLE_ROWS;
00210 
00211     // Returns the path of the CASA top-level directory.  This value is
00212     // retrieved from the environment variables the first time it is called,
00213     // and then returns the stored result on subsequent calls.
00214     static String aipspath();
00215 
00216     // Returns the absolute path of the ~/.casa directory.  This value is
00217     // retrieved from the environment variables the first time it is called,
00218     // and then returns the stored result on subsequent calls.
00219     static String dotCasapyDir();
00220     
00221     // Converts a vector<int> to an IPosition.
00222     static IPosition ipos(std::vector<int>& d);
00223     
00224     // Converts an IPosition to a vector<int>.
00225     static std::vector<int> ipos(IPosition& d);
00226     
00227     // Increments the given dimension, using the given shape as a maximum.
00228     static bool increment(IPosition& shape, IPosition& d);
00229     
00230     // Increments the given dimension, using the given shape as a maximum.
00231     static bool increment(std::vector<int>& shape, std::vector<int>& d);
00232     
00233     // Inserts the given widget into the given placeholder frame.
00234     static void insert(QFrame* frame, QWidget* widget);
00235     
00236     // Inserts the given layout into the given placeholder frame.
00237     static void insert(QFrame* frame, QLayout* layout);
00238     
00239     
00240     /* Data Types and Related Methods */
00241 
00242     // Table data types.
00243     // <group>
00244     static const String TYPE_STRING;
00245     static const String TYPE_DOUBLE;
00246     static const String TYPE_FLOAT;
00247     static const String TYPE_INT;
00248     static const String TYPE_UINT;
00249     static const String TYPE_BOOL;
00250     static const String TYPE_CHAR;
00251     static const String TYPE_UCHAR;
00252     static const String TYPE_SHORT;
00253     static const String TYPE_COMPLEX;
00254     static const String TYPE_DCOMPLEX;
00255     static const String TYPE_TABLE;
00256     static const String TYPE_RECORD;
00257     static const String TYPE_DATE;
00258 
00259     static const String TYPE_ARRAY_STRING;
00260     static const String TYPE_ARRAY_DOUBLE;
00261     static const String TYPE_ARRAY_FLOAT;
00262     static const String TYPE_ARRAY_INT;
00263     static const String TYPE_ARRAY_UINT;
00264     static const String TYPE_ARRAY_BOOL;
00265     static const String TYPE_ARRAY_CHAR;
00266     static const String TYPE_ARRAY_UCHAR;
00267     static const String TYPE_ARRAY_SHORT;
00268     static const String TYPE_ARRAY_COMPLEX;
00269     static const String TYPE_ARRAY_DCOMPLEX;
00270     // </group>
00271 
00272     // Unsupported types
00273     // static const String TYPE_USHORT;
00274     // static const String TYPE_ARRAY_USHORT;
00275     // static const String TYPE_OTHER;
00276     
00277     // Return a vector containing all the valid data types.
00278     static std::vector<String>* allTypes();
00279 
00280     // Return a vector containing all the valid array data types.
00281     static std::vector<String>* arrayTypes();
00282 
00283     // Return a vector containing all the valid non-array data types.
00284     static std::vector<String>* nonArrayTypes();
00285 
00286     // The comments for Double fields that indicate that they should be
00287     // interpreted as a date.
00288     static const String COMMENT_DATE;
00289     static const String COMMENT_TIMP;
00290     static const String COMMENT_TIMP2;
00291 
00292     // Convert a CASA DataType enum to its String equivalent.
00293     static String typeName(DataType dt);
00294 
00295     // Returns a human-readable name for the given type.
00296     static String typeName(String type);
00297 
00298     // Converts the given type into its corresponding VOTable type.  See
00299     // http://www.ivoa.net/Documents/REC/VOTable/VOTable-20040811.html#ToC11
00300     static String VOType(String& type);
00301 
00302     // Returns true if the given type is a table type, false otherwise.
00303     static bool typeIsTable(String& type);
00304 
00305     // Returns true if the given type is an array type, false otherwise.
00306     static bool typeIsArray(String& type);
00307 
00308     // Returns true if the given type is plottable, false otherwise.
00309     static bool typeIsPlottable(String& type);
00310 
00311     // Returns true if the given type is numberable, false otherwise.
00312     static bool typeIsNumberable(String& type);
00313 
00314     // Returns true if the given type can be used as an index (i.e.,
00315     // integer-like), false otherwise.
00316     static bool typeIsIndexable(String& type);
00317 
00318     // Retruns true if the given type is a complex or array of complex types,
00319     // false otherwise.
00320     static bool typeIsComplex(String& type);
00321 
00322     // Returns the value type from the given array type.  For example,
00323     // arrayType(TYPE_ARRAY_STRING) = TYPE_STRING.
00324     static String arrayType(String& at);
00325 
00326     // Returns true if the given value is valid for the given type, false
00327     // otherwise.
00328     static bool valueIsValid(String& value, String& type);
00329 
00330     // Formats the given value for the given data type and returns the
00331     // formatted value.
00332     static String formatValue(String& value, String& type);
00333 
00334     // Converts the given value of the given type to a double and return it.
00335     // Returns -1 for invalid doubles.
00336     static double valueToDouble(String& value, String& type);
00337     
00338     // Converts the given String in date format (year-month-day-hour:min:sec)
00339     // to its double representation.  The double returned is in modified
00340     // julian seconds.
00341     static double date(String d);
00342 
00343     // Converts the given double into a String in date format
00344     // (year-month-day-hour:min:sec).  The input double should be in modified
00345     // julian seconds.
00346     static String date(const double d, const int numDecimals = -1);
00347     
00348     // Holds the default number of decimals displayed in a number.
00349     static const int DEFAULT_DECIMALS;
00350     
00351     // Holds the default number of decimals displayed in a date.
00352     static const int DEFAULT_DATE_DECIMALS;
00353     
00354     // Returns true if the given String contains a valid date format, false
00355     // otherwise.  A valid date format has %y, %m, %d, %n, and %s appear
00356     // exactly once.  %y = year, %m = month, %d = day of month, %n = minute
00357     // %s = second; all fields are integers.
00358     static bool dateFormatIsValid(String& d);
00359 
00360     // Converts a String in complex format (a,b) into a pair of doubles.
00361     static std::pair<double, double> toComplex(String str);
00362     
00363     // String used in parsing arrays.
00364     static const String ARRAY_AXES_LENGTHS;
00365 
00366 
00367     /* XML Driver Constants/Defaults */
00368 
00369     // XML token names that are used in table parsing.
00370     // <group>
00371     static const String XML_VOTABLE;
00372     static const String XML_RESOURCE;
00373     static const String XML_TABLE;
00374     static const String XML_TOTAL;
00375     static const String XML_FIELD;
00376     static const String XML_KEYWORD;
00377     static const String XML_COLUMNKW;
00378     static const String XML_RWINFO;
00379     static const String XML_DATA;
00380     static const String XML_TABLEDATA;
00381     static const String XML_TR;
00382     static const String XML_TD;
00383     static const String XML_INSERTROW;
00384     static const String XML_REMOVEROW;
00385     static const String XML_TRUE;
00386     static const String XML_FALSE;
00387     static const String XML_ROW;
00388     static const String XML_NAME;
00389 
00390     static const String XML_ID;
00391     static const String XML_KEYWORD_NAME;
00392     static const String XML_KEYWORD_TYPE;
00393     static const String XML_KEYWORD_VAL;
00394     static const String XML_COLKW_COL;
00395     static const String XML_FIELD_NAME;
00396     static const String XML_FIELD_TYPE;
00397     static const String XML_FIELD_UNIT;
00398     static const String XML_FIELD_UCD;
00399     static const String XML_FIELD_REF;
00400     static const String XML_FIELD_PRECISION;
00401     static const String XML_FIELD_WIDTH;
00402     // </group>
00403 
00404     // Error text that is thrown/returned on an empty table or row.
00405     static const String ERROR_EMPTY;
00406 
00407     // Converts a char* to an XMLCh*.  See XMLString::transcode().
00408     static const XMLCh* xstr(char* str);
00409 
00410     // Converts a String to an XMLCh*.  See XMLString::transcode().
00411     static const XMLCh* xstr(String str);
00412 
00413     // Converts an XMLCh* to a String.  See XMLString::transcode().
00414     static String xstr(XMLCh* str);
00415 
00416     // Converts a const XMLCh* to a String.  See XMLString::transcode().
00417     static String xstr(const XMLCh* str);
00418 
00419 
00420     /* String and Number Methods */
00421 
00422     // Converts the given int into its String representation and returns it.
00423     static String itoa(int n);
00424     
00425     // Converts the given unsigned int into its String representation and
00426     // returns it.
00427     static String uitoa(unsigned int n);
00428     
00429     // Converts the given short int into its String representation and
00430     // returns it.
00431     static String sitoa(short int n);
00432 
00433     // Converts the given float into its String representation and returns it.
00434     static String ftoa(float f, int decimals = -1, bool scientific = false);
00435 
00436     // Converts the given double into its String representation and returns it.
00437     static String dtoa(double d, int decimals = -1, bool scientific = false);
00438 
00439     // Converts the given String into its int representation.  Returns the
00440     // result of sscanf.
00441     static int atoi(String& str, int* i);
00442     
00443     // Converts the given String into its unsigned int representation.  Returns
00444     // the result of sscanf.
00445     static int atoui(String& str, unsigned int* i);
00446     
00447     // Converts the given String into its short int representation.  Returns
00448     // the result of sscanf.
00449     static int atosi(String& str, short int* i);
00450 
00451     // Converts the given String into its float representation.  Returns the
00452     // result of sscanf.
00453     static int atof(String& str, float* f);
00454 
00455     // Converts the given String into its double representation.  Returns the
00456     // result of sscanf.
00457     static int atod(String& str, double* d);
00458     
00459     // Rounds the given double to the nearest int and returns it.
00460     static int round(double d);
00461 
00462     // Returns true if the given char is a whitespace, false otherwise.
00463     static bool isWS(char c);
00464 
00465     // Trims the given String of its leading and trailing whitespace using
00466     // String::erase().
00467     static void strtrim(String& str);
00468 
00469     // Converts all upper-case letters to lower-case letters in the given
00470     // String.
00471     static void toLower(String& str);
00472 
00473     // Returns the index of the next instance of a whitespace character in the
00474     // given String from the given index, or the string's length if there is none.
00475     static unsigned int findWS(String& str, int index = 0);
00476 
00477     // Returns the index of the next instance of the find String in the given
00478     // String starting from the given index, or str's length if there is none.
00479     static unsigned int findIgnoreCase(String& str, String& find,
00480                                        int index = 0);
00481 
00482     // Returns true if the two Strings are equal (ignoring case), false
00483     // otherwise.
00484     static bool equalsIgnoreCase(String str1, String str2);
00485 
00486     // Returns the name of the file from the given path (the last part of the
00487     // path).
00488     static String nameFromPath(String& path);
00489 
00490     // Returns the directory from the given path (all but the last part of the
00491     // path).
00492     static String dirFromPath(String& path);
00493 
00494 
00495     /* TBConnection Constants/Defaults */
00496 
00497     // Help descriptions used by TBConnection.
00498     // <group>
00499     static const String OPEN_TEXT_LOCAL;
00500     static const String OPEN_TEXT_REMOTE;
00501     static const String OPEN_TEXT_HOST;
00502     static const String OPEN_TEXT_PORT;
00503     static const String OPEN_TEXT_LOCATION;
00504     static const String OPEN_TEXT_DIRECT;
00505     static const String OPEN_TEXT_XML;
00506     static const String OPEN_TEXT_HOME;
00507     static const String OPEN_TEXT_DOM;
00508     static const String OPEN_TEXT_SAX;
00509     static const String OPEN_TEXT_START;
00510     static const String OPEN_TEXT_NUM;
00511     // </group>
00512 
00513 
00514     /* Help Constants/Defaults */
00515 
00516     // Constants for the help system.
00517     // <group>
00518     static const String HELP_DIR;
00519     static const String HELP_INDEX;
00520     static const String HELP_XML;
00521     static const String HELP_XML_HELP;
00522     static const String HELP_XML_CATEGORY;
00523     static const String HELP_XML_NAME;
00524     static const String HELP_XML_GROUP;
00525     static const String HELP_XML_ITEM;
00526     // </group>
00527 
00528 
00529     /* Plotting Constants/Defaults */
00530 
00531     // Plotting defaults.
00532     // <group>
00533     
00534     // The default plotter implementation for the browser.
00535     static const Plotter::Implementation defaultPlotterImplementation;
00536     
00537     // Returns a default line to use with new plots, using the given factory
00538     // (should match the implementation of defaultPlotterImplementation).
00539     static PlotLinePtr defaultPlotLine(PlotFactoryPtr factory);
00540     
00541     // Returns a default plot symbol to use with new plots, using the given
00542     // factory (should match the implementation of
00543     // defaultPlotterImplementation).
00544     static PlotSymbolPtr defaultPlotSymbol(PlotFactoryPtr factory);
00545 
00546 
00547     /* View Constants/Defaults */
00548 
00549     // View constants.
00550     // <group>
00551     static const String VIEW_SAVE_LOC;
00552 
00553     static const String VIEW_DOCUMENT;
00554     static const String VIEW_VIEW;
00555     static const String VIEW_LASTDIR;
00556     static const String VIEW_HISTLIMIT;
00557     static const String VIEW_TABLE;
00558     static const String VIEW_LOCATION;
00559     static const String VIEW_SELECTED;
00560     static const String VIEW_TAQL;
00561     static const String VIEW_HIDDEN;
00562     static const String VIEW_HIDDEN_LENGTH;
00563     static const String VIEW_VISIND;
00564     static const String VIEW_ROWS;
00565     static const String VIEW_ROWS_FROM;
00566     static const String VIEW_ROWS_NUM;
00567     static const String VIEW_FILTER;
00568     static const String VIEW_FILTER_RULE;
00569     static const String VIEW_FILTER_RULE_FIELD;
00570     static const String VIEW_FILTER_RULE_COMPARATOR;
00571     static const String VIEW_FILTER_RULE_VALUE;
00572     static const String VIEW_FILTER_RULE_VALUE2;
00573     static const String VIEW_FILTER_RULE_NOT;
00574     static const String VIEW_FILTER_RULE_ANY;
00575     static const String VIEW_FILTER_RULE_TYPE;
00576     static const String VIEW_FORMATS;
00577     static const String VIEW_FORMAT;
00578     static const String VIEW_FORMAT_COL;
00579     static const String VIEW_FORMAT_DECIMALS;
00580     static const String VIEW_FORMAT_SFORMAT;
00581     static const String VIEW_FORMAT_BFORMAT;
00582     static const String VIEW_FORMAT_DFORMAT;
00583     static const String VIEW_FORMAT_VTHRESHOLD;
00584     static const String VIEW_FORMAT_ALLFONT;
00585     static const String VIEW_FORMAT_FONT;
00586     static const String VIEW_FORMAT_COLOR;
00587     static const String VIEW_FORMAT_FAMILY;
00588     static const String VIEW_FORMAT_SIZE;
00589     static const String VIEW_FORMAT_BOLD;
00590     static const String VIEW_FORMAT_ITALICS;
00591     static const String VIEW_FORMAT_ULINE;
00592     static const String VIEW_FORMAT_STRIKE;
00593     static const String VIEW_SORT;
00594     static const String VIEW_NAME;
00595     static const String VIEW_SORT_ASCENDING;
00596     // </group>
00597     
00598 private:
00599     // Path to the CASA top-level directory.
00600     static String AIPS_PATH;
00601 
00602     // Common string in the TBConnection defaults.
00603     static const String OPEN_PAGE;
00604 
00605     // Holds the absolute location of the ~/.casa directory.
00606     static String DOT_CASAPY_DIR;
00607 };
00608 
00609 }
00610 
00611 #endif /*CONSTANTS_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1