Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "vil_open.h"
00010
00011 #include <vcl_cstring.h>
00012
00013 #include <vil/vil_stream_fstream.h>
00014
00015 #include <vil/vil_stream_core.h>
00016 #include <vil/vil_stream_url.h>
00017
00018
00019 vil_stream *vil_open(char const* what, char const* how)
00020 {
00021
00022 if (!what || !*what)
00023 return 0;
00024
00025
00026 #ifdef VIL_USE_FSTREAM64
00027 vil_stream *is = new vil_stream_fstream64(what, how);
00028 #else //VIL_USE_FSTREAM64
00029 vil_stream *is = new vil_stream_fstream(what, how);
00030 #endif //VIL_USE_FSTREAM64
00031
00032 #if 0
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifdef VIL_USE_FSTREAM64
00043 vil_stream *is = new vil_stream_fstream64(what, "r+");
00044 #else //VIL_USE_FSTREAM64
00045 vil_stream *is = new vil_stream_fstream(what, "r+");
00046 #endif //VIL_USE_FSTREAM64
00047 #endif
00048 if (!is->ok()) {
00049
00050 is->ref();
00051 is->unref();
00052 is = 0;
00053 }
00054
00055 if (!is) {
00056
00057 int l = (int)vcl_strlen(what);
00058 if (l > 4 && vcl_strncmp(what, "gen:", 4) == 0) {
00059 if (vcl_strcmp(how, "r") == 0) {
00060
00061 vil_stream_core *cis = new vil_stream_core();
00062 cis->write(what, l+1);
00063 is = cis;
00064 }
00065 else {
00066 vcl_cerr << __FILE__ ": cannot open gen:* for writing\n";
00067 }
00068 }
00069 }
00070 if (is && !is->ok()) {
00071
00072 is->ref();
00073 is->unref();
00074 is = 0;
00075 }
00076
00077 if (!is) {
00078
00079 int l = (int)vcl_strlen(what);
00080 if (l > 4 && vcl_strncmp(what, "http://", 7) == 0) {
00081 if (vcl_strcmp(how, "r") == 0) {
00082 is = new vil_stream_url(what);
00083 }
00084 else
00085 vcl_cerr << __FILE__ ": cannot open URL for writing (yet)\n";
00086 }
00087 }
00088 if (is && !is->ok()) {
00089
00090 is->ref();
00091 is->unref();
00092 is = 0;
00093 }
00094
00095 return is;
00096 }
00097
00098 #if defined(VCL_WIN32) && VXL_USE_WIN_WCHAR_T
00099
00100
00101
00102
00103 vil_stream *vil_open(wchar_t const* what, char const* how)
00104 {
00105
00106 if (!what || !*what)
00107 return 0;
00108
00109
00110 #ifdef VIL_USE_FSTREAM64
00111 vil_stream *is = new vil_stream_fstream64(what, how);
00112 #else //VIL_USE_FSTREAM64
00113 vil_stream *is = new vil_stream_fstream(what, how);
00114 #endif //VIL_USE_FSTREAM64
00115
00116 if (!is->ok()) {
00117
00118 is->ref();
00119 is->unref();
00120 is = 0;
00121 }
00122
00123 #if 0 // TODO: add wchar_t support in vil_stream_core
00124 if (!is) {
00125
00126 int l = wcslen(what);
00127 if (l > 4 && wcsncmp(what, L"gen:", 4) == 0) {
00128 if (vcl_strcmp(how, "r") == 0) {
00129
00130 vil_stream_core *cis = new vil_stream_core();
00131 cis->write(what, l+1);
00132 is = cis;
00133 }
00134 else {
00135 vcl_cerr << __FILE__ ": cannot open gen:* for writing\n";
00136 }
00137 }
00138 }
00139 if (is && !is->ok()) {
00140
00141 is->ref();
00142 is->unref();
00143 is = 0;
00144 }
00145 #endif
00146
00147 #if 0 // TODO: add wchar_t support in vil_stream_url
00148 if (!is) {
00149
00150 int l = vcl_strlen(what);
00151 if (l > 4 && vcl_strncmp(what, "http://", 7) == 0) {
00152 if (vcl_strcmp(how, "r") == 0) {
00153 is = new vil_stream_url(what);
00154 }
00155 else
00156 vcl_cerr << __FILE__ ": cannot open URL for writing (yet)\n";
00157 }
00158 }
00159 if (is && !is->ok()) {
00160
00161 is->ref();
00162 is->unref();
00163 is = 0;
00164 }
00165 #endif
00166
00167 return is;
00168 }
00169
00170 #endif //defined(VCL_WIN32) && VXL_USE_WIN_WCHAR_T