basix_doc 0.1
|
00001 00002 /****************************************************************************** 00003 * MODULE : port.cpp 00004 * DESCRIPTION: Abstract input and output 00005 * COPYRIGHT : (C) 2010 Joris van der Hoeven 00006 ******************************************************************************* 00007 * This software falls under the GNU general public license and comes WITHOUT 00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. 00009 * If you don't have this file, write to the Free Software Foundation, Inc., 00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00011 ******************************************************************************/ 00012 00013 #include <basix/port.hpp> 00014 #include <basix/string.hpp> 00015 00017 00018 namespace mmx { 00019 00020 bool texmacs_mode= false; 00021 bool math_mode= false; 00022 00023 /****************************************************************************** 00024 * Default implementations of virtual methods 00025 ******************************************************************************/ 00026 00027 bool 00028 port_rep::is_output_port () { 00029 return false; 00030 } 00031 00032 bool 00033 port_rep::is_input_port () { 00034 return false; 00035 } 00036 00037 bool 00038 port_rep::error_flag () { 00039 return false; 00040 } 00041 00042 string 00043 port_rep::error_message () { 00044 return ""; 00045 } 00046 00047 bool 00048 port_rep::busy () { 00049 return false; 00050 } 00051 00052 nat 00053 port_rep::can_write () { 00054 return 0; 00055 } 00056 00057 nat 00058 port_rep::can_read () { 00059 return 0; 00060 } 00061 00062 void 00063 port_rep::write (const char* s, nat n) { 00064 (void) s; (void) n; 00065 mmerr << "port= " << expression () << lf; 00066 ERROR ("output port expected"); 00067 } 00068 00069 void 00070 port_rep::read (char* s, nat n) { 00071 (void) n; 00072 mmerr << "port= " << expression () << lf; 00073 ERROR ("input port expected"); 00074 } 00075 00076 bool 00077 port_rep::wait (int msecs) { 00078 (void) msecs; 00079 return false; 00080 } 00081 00082 void 00083 port_rep::flush () { 00084 } 00085 00086 port 00087 port_rep::accept () { 00088 mmerr << "port= " << expression () << lf; 00089 ERROR ("socket server port expected"); 00090 } 00091 00092 port 00093 port_rep::component (const string& name) { 00094 mmerr << "port= " << expression () << lf; 00095 ERROR ("composite port expected"); 00096 } 00097 00098 void 00099 port_rep::format (const print_format& fm) { 00100 mmerr << "port= " << expression () << lf; 00101 ERROR ("formatting port expected"); 00102 } 00103 00104 string error_message (const port& p) { 00105 return inside (p)->error_message (); } 00106 port component (const port& p, const string& name) { 00107 return inside (p)->component (name); } 00108 00109 /****************************************************************************** 00110 * Error ports (for ports which did not open, for instance) 00111 ******************************************************************************/ 00112 00113 class error_port_rep: public port_rep { 00114 string s; 00115 00116 public: 00117 virtual syntactic expression () const { 00118 return syn ("error_port", syntactic (quote (s))); } 00119 bool error_flag () { return true; } 00120 string error_message () { return s; } 00121 00122 public: 00123 inline error_port_rep (const string& s2): s (s2) {} 00124 }; 00125 00126 port 00127 error_port (const string& s) { 00128 return (port_rep*) new error_port_rep (s); 00129 } 00130 00131 port::port (): rep ((port_rep*) new error_port_rep ("no port")) {} 00132 00133 } // namespace mmx