cgma
CubitUtil.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CubitUtil.hpp
00003 //
00004 // Purpose       : This file contains utility functions that can be used
00005 //                 throughout Cubit.
00006 //
00007 // Special Notes : This is a pure virtual class, to prevent instantiation.
00008 //                 All functions are static, called like this:
00009 //                 CubitUtil::function_name();
00010 //
00011 // Creator       : Darryl Melander
00012 //
00013 // Date          : 06/08/98
00014 //
00015 // Owner         : Darryl Melander
00016 //-------------------------------------------------------------------------
00017 
00018 
00019 #ifndef CUBIT_UTIL_HPP
00020 #define CUBIT_UTIL_HPP
00021 
00022 #include <cstring>
00023 #include "DLIList.hpp"
00024 #include "CubitDefines.h"
00025 #include "CGMUtilConfigure.h"
00026 #include "CubitString.hpp"
00027 
00028 class CubitEntity;
00029 
00030 class CUBIT_UTIL_EXPORT CubitUtil
00031 {
00032 public:
00033   
00034   static void set_digits(int new_digits);
00035   static int get_digits();
00036 
00037    static void convert_string_to_lowercase (char *string);
00038    static int  strcmp_case_insensitive     (const char *s1, const char *s2);
00039    static int  strncmp_case_insensitive    (const char *s1, const char *s2,
00040                                             int n);
00041 
00042   static void list_ids( const char *const heading,
00043                   const DLIList<CubitEntity*> &entity_list,
00044                   int should_sort = CUBIT_FALSE,
00045                   int report_once = CUBIT_FALSE,
00046                   int wrap = 80 );
00047 
00048   static void sort_and_print_ids( const char *const heading,
00049                            DLIList<int> &id_list,
00050                            int should_sort = CUBIT_FALSE,
00051                            int report_once = CUBIT_FALSE,
00052                            int wrap = 80);
00053 
00054 
00055 
00056   static void list_entity_ids( const char *pre_string, 
00057                                const DLIList<CubitEntity*> &entity_list, 
00058                                int width = 80, const char *post_string = "\n",
00059                                int sort = CUBIT_TRUE, int unique = CUBIT_TRUE,
00060                                int tab = 3, const char *sep_string = ",",
00061                                const char *post_string_none = "none\n");
00062   
00063   static void list_entity_ids( const char *pre_string, 
00064                                DLIList<int> &id_list,
00065                                int width = 80, 
00066                                const char *post_string = "\n",
00067                                int sort = CUBIT_TRUE, int unique = CUBIT_TRUE,
00068                                int tab_len = 3, const char *sep_string = ",",
00069                                const char *post_string_none = "none\n");
00070   
00071   static CubitString get_entity_ids_str( const char *pre_string, DLIList<int> &int_list, 
00072                                          int width = 80, const char *post_string = "\n",
00073                                          int sort = CUBIT_TRUE, int unique = CUBIT_TRUE,
00074                                          int left_tab = 3, const char *sep_string = ",",
00075                                          const char *post_string_none = "none\n");
00076 
00077   static void process_entity_ids( int method,
00078                                   CubitString &ret_str,
00079                                   const char *pre_string, 
00080                                   DLIList<int> &id_list,
00081                                   int max_len, 
00082                                   const char *post_string,
00083                                   int sort, int unique,
00084                                   int tab_len, const char *sep_string,
00085                                   const char* post_string_none = "none\n");
00086   
00087   static int int_len( int num );
00088     //- Finds the number of spaces required to print an integer number
00089 
00090   static void set_file_ptr( FILE* file_ptr );
00091   static void reset_file_ptr();
00092   static FILE* get_file_ptr();
00093   //- Used to optionally have list_entity_ids or get_entity_ids_str output dumped
00094   //- to a file as well.
00095 
00096   static CubitBoolean compare( const char* a, const char* b )
00097     { return ( a != NULL && b != NULL && 0 == strcmp(a, b) ); }
00098 
00099   static CubitSense opposite_sense(CubitSense sense);
00100     //- return the sense opposite from sense
00101 
00102   static CubitString get_temporary_filename();
00103     //- function to get a temporary filename, the file is created empty before return
00104 
00105   static int string_length( const char* string, int tabsize = 8 );
00106   static void print_columns( const std::vector<CubitString>& array,
00107                              const CubitString& indent = CubitString());
00108 
00109     //does the same thing as strdup... strdup is not supported by some
00110     // compilers
00111   static char* util_strdup(const char *s1);
00112     //a corresponding free for the above function... mainly calls free().
00113   static void util_strdup_free(char* s1){free(s1);}
00114 
00115   static void cubit_sleep(int duration_in_seconds);
00116 
00117   static CubitBoolean file_exist(const char* buffer);
00118   static CubitBoolean file_exist(const CubitString& buffer);
00119 
00120   // get an environment variable
00121   static CubitString getenv(const CubitString& str);
00122   static void setenv(const CubitString& var, const CubitString& value);
00123 
00124   static CubitString get_computer_name();
00125   static CubitString get_os();
00126 
00127   static int num_cpu();
00128   
00129 private:
00130   CubitUtil(){}
00131 
00132   static FILE *fp;
00133 
00134 };
00135 
00136 inline void
00137 CubitUtil::set_file_ptr( FILE* file_ptr )
00138 {fp=file_ptr;}
00139 
00140 inline void
00141 CubitUtil::reset_file_ptr()
00142 {fp=NULL;}
00143 
00144 inline CubitSense CubitUtil::opposite_sense( CubitSense sense )
00145 {
00146    assert( sense == CUBIT_UNKNOWN ||
00147            sense == CUBIT_FORWARD ||
00148            sense == CUBIT_REVERSED );
00149    if ( sense == CUBIT_UNKNOWN ) return CUBIT_UNKNOWN;
00150    else {
00151       CubitSense opp_sense = (CubitSense) (1 - sense);
00152       return opp_sense;
00153    }
00154 }
00155 
00156 inline FILE*
00157 CubitUtil::get_file_ptr()
00158 {return fp;}
00159 #endif
00160 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines