Programming - various C/C++ code |
July 24
2003 |
While working on a set of CGI programs I realized I needed
to write some useful, reusable, code for manipulating various CGI tasks.
The C++ classes use STL vector and string. The result of my work is listed
below.
Download:
d_env.cpp - wrapper class for the environment table
Example:
d_env blah;
cout << blah << endl;
cout << d_env.gets( "request_uri")
<< endl; |
|
// declares class
// displays the entire environment table
// displays the result of that var |
d_exec.cpp - wrapper class for programmatically
accessing output of an executed program
Example:
d_exec blah;
blah.prun( "/bin/ls -l 2>&1" );
cout << blah.size() << endl;
cout << blah << endl;
cout << blah.data[3]; |
|
// declares the class
// runs command, "2>&1" is there to force
// stderr display to show up in the program
// spits out number of output lines
// spits out the program result
// spits out line #3 of the output |
d_stdio.cpp - wrapper class for the stdio data
Example:
d_stdio blah;
blah.spit();
cout << blah.data[3];
cout << blah.gets( "p1" ); |
|
// declares the class
// I was too lazy to write friend ostream so I just
// wrote a function to display everything
// displays stdio line #3
// returns line containing p1 |
d_sql.cpp - simple wrapper class for mysql
Example:
d_sql blah;
blah.d_host = "hostname";
blah.d_user = "username";
blah.d_pwd = "pass";
blah.d_db = "database";
blah.d_port = 3306;
blah.conn();
blah.query( "show tables" );
blah.close();
cout << blah.data[3];
|
|
// declares class
// sets parameters
// connects to server
// queries
// closes connection
// spits out line #3 (if it exists), furthermore,
// .head and .head2 contain information about
// the database table |
d_html.cpp - simple class for creating / displaying html tables
Example:
d_html blah(3,4);
blah.resize( 3,3 );
blah.set( 1, 1, "bugaboo");
cout << blah; |
|
// declares class, creates 3 x 4 table
// resizes table to 3 x 3 cells
// writes "bugaboo" to cell (1,1)
// spits out the html code to display the table |
useful.cpp - some helpful functions for string to integer
conversion
Example:
int test;
string blah;
test = str2int("4");
blah = int2str(test); |
|
// declare integer to test the program with
// declare string
// converts string to integer
// converts integer to string |

..back to main page |