Skip site navigation (1)Skip section navigation (2)
Date:      12 Apr 2002 03:35:10 -0700
From:      Max Okumoto <okumoto@ucsd.edu>
To:        freebsd-libh@FreeBSD.ORG
Subject:   cleanup of HSystem (stage 1)
Message-ID:  <hfbscp6w81.fsf@multivac.sdsc.edu>

next in thread | raw e-mail | index | archive | help

* (HSystem.hh) Cleanup API by reducing number of externally accesable
  types and methods.

* (HSystem.hh) Cleanup API by changing the following output routines to
  private, and added gen_file() which calls them in sequence.
	gen_header()
	gen_classes_interfaces()
	gen_register_command_access()
	gen_footer()

* (HSystem.hh) Declared new types to be used in stage 2 of cleanup
	ClassDesc, MethodDesc, CallBackDesc

* (HSystem.hh) Flaged a problem in the copy constructor.

* (HSystem.hh) Added Doxygen style comments.

* (HSystem.hh) Corrected comment for build_systems().

* (tcl_interface_gen.cc) Cleaned up main() by using more descriptive variable
  names.

* (tcl_interface_gen.cc) Cleaned up main() by using new gen_file() method.

* (tcl_interface_gen.cc) Started mucking white space.


Index: include/HSystem.hh
===================================================================
RCS file: /home/libh/cvs/libh/include/HSystem.hh,v
retrieving revision 1.5
diff -u -r1.5 HSystem.hh
--- include/HSystem.hh	2002/04/11 23:35:52	1.5
+++ include/HSystem.hh	2002/04/12 10:03:25
@@ -37,75 +37,129 @@
 #ifndef HSystem_hh
 #define HSystem_hh
 
-#ifndef LanguageInterface_hh
 #include "LanguageInterface.hh"
-#endif
 
-#include <iostream.h>
-
-#include <set>
+#include <iostream>
 #include <list>
-
-//======================================================================
+#include <set>
 
-class HSystem
-{
-  public:
-     typedef list<const LanguageInterface::Object::ClassDescription*> Descriptions;
-     typedef set<string> Includes;
-     typedef list<const char*> CommandAccessToRegister;
-     typedef list<pair<string,string> > StaticMethods;
-
-     HSystem( const string& aName )
-          : name( aName ) {}
-     HSystem( const HSystem& aHSystem )
-          : name( aHSystem.name ) {}
-
-     void add_class( const LanguageInterface::Object::ClassDescription* class_desc, const string& include_file )
-          {
-               descriptions.push_back( class_desc );
-               includes.insert( include_file );
-          }
-
-     void gen_header( ostream& out );
-     void gen_classes_interfaces( ostream& out );
-     void gen_register_command_access( ostream& out );
-     void gen_footer( ostream& out );
-
-     Descriptions descriptions;
-     Includes includes;
-     CommandAccessToRegister commandAccessToRegister;
-     StaticMethods staticMethods;
-
-     string name;
-     bool operator < ( const HSystem& toCompare ) const { return name < toCompare.name; }
-     bool operator == ( const HSystem& toCompare ) const { return name == toCompare.name; }
-
-  private:
-     void gen_class_header( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     void gen_callback_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     void gen_dynamic_methods_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     void gen_static_method_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription );
-     string gen_result_to_obj( LanguageInterface::Object::MethodDescription::Value t );
-     string gen_method_argument( LanguageInterface::Object::MethodDescription::Value t, int argno, int method_argno, bool last_arg_in_set_method );
+/**
+ * Represent a libh subsystem object.
+ */
+class HSystem {
+    typedef LanguageInterface::Object::ClassDescription		ClassDesc;
+    typedef LanguageInterface::Object::MethodDescription	MethodDesc;
+    typedef LanguageInterface::Object::CallbackDescription	CallBackDesc;
+
+    typedef list<const ClassDesc *>	Descriptions;
+    typedef set<string>			Includes;
+    typedef list<const char *>		CommandAccessToRegister;
+    typedef list<pair<string,string> >	StaticMethods;
+
+    Descriptions		descriptions;
+    Includes			includes;
+    CommandAccessToRegister	commandAccessToRegister;
+    StaticMethods		staticMethods;
+
+public:
+    const string	name; /**< Name of the subsystem. */
+
+    /**
+     * Constructor.
+     */
+    HSystem(const string& aName)
+	: name(aName) {}
+
+    /**
+     * Copy constructor.  XXX This is broken!  None of the other state is
+     * copied!
+     */
+    HSystem(const HSystem& aHSystem)
+	: name(aHSystem.name) {}
+
+    /**
+     * LessThan operator.
+     */
+    bool operator<(const HSystem& rhs) const { return name < rhs.name; }
+
+    /**
+     * Equivilance operator.
+     */
+    bool operator==(const HSystem& rhs) const { return name == rhs.name; }
+
+    /**
+     * Adds the class description and include file to the system definition.
+     *
+     * @param class_desc
+     * @param include_file
+     *
+     * @see find_classes_descriptions.pl
+     */
+    void
+    add_class(const ClassDesc *class_desc, const string& include_file)
+    {
+	descriptions.push_back(class_desc);
+	includes.insert(include_file);
+    }
+
+    /**
+     * Generate libh subsystem tcl interface text.
+     *
+     * @param out	stream to send text.
+     */
+    void
+    gen_file(ostream& out)
+    {
+	gen_header(out);
+	gen_classes_interfaces(out);
+	gen_register_command_access(out);
+	gen_footer(out);
+    }
+
+private:
+    /**
+     * Output header and includes. The output text contains a
+     * warning that it is a generated source file.
+     *
+     * @param out	stream to send text.
+     */
+    void gen_header(ostream& out) const;
+
+    /**
+     * @param out	stream to send text.
+     */
+    void gen_classes_interfaces(ostream& out);
+
+    /**
+     * @param out	stream to send text.
+     */
+    void gen_register_command_access(ostream& out);
+
+    /**
+     * @param out	stream to send text.
+     */
+    void gen_footer(ostream& out) const;
+
+    void gen_class_header(ostream& out, const ClassDesc* aClassDescription);
+    void gen_callback_interfaces(ostream& out, const ClassDesc* aClassDescription);
+    void gen_dynamic_methods_interfaces(ostream& out, const ClassDesc* aClassDescription);
+    void gen_static_method_interfaces(ostream& out, const ClassDesc* aClassDescription);
+    string gen_result_to_obj(MethodDesc::Value t);
+    string gen_method_argument(MethodDesc::Value t, int argno, int method_argno, bool last_arg_in_set_method);
 
 }; // class HSystem
 
-//======================================================================
-
 /**
  * a set of systems
  */
 typedef set<HSystem> Systems;
 
-//======================================================================
-
 /**
  * Initialize a subsystem and register it.
  *
  * The implementation of this function must add the subsystem to the
  * Systems set. The subsystem added must include all classes
- * description the subsystems wishes to make accessible from TCL.
+ * description the subsystems wishes to make accessible to TCL.
  *
  * @note this function is created by find_classes_descriptions.pl for
  * each subsystem.
@@ -113,8 +167,6 @@
  * @see find_classes_descriptions.pl
  * @param systems      the set of HSystem objects to add the subsystem to
  */
-void build_systems( Systems& systems );
-
-//======================================================================
+void build_systems(Systems& systems);
 
 #endif // HSystem_hh
Index: lib/tcl/tcl_interface_gen.cc
===================================================================
RCS file: /home/libh/cvs/libh/lib/tcl/tcl_interface_gen.cc,v
retrieving revision 1.7
diff -u -r1.7 tcl_interface_gen.cc
--- lib/tcl/tcl_interface_gen.cc	2001/09/20 21:17:50	1.7
+++ lib/tcl/tcl_interface_gen.cc	2002/04/12 10:03:27
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 1998-2001 The FreeBSD Project
+ * Copyright (c) 1998-2002 The FreeBSD Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,13 +33,8 @@
 // Eugene Skepner <eu@qub.com>
 // $Id: tcl_interface_gen.cc,v 1.45 1999/01/06 15:17:48 eugene Exp $
 
-#ifndef HSystem_hh
 #include "HSystem.hh"
-#endif
-
-#ifndef String_hh
 #include "String.hh"
-#endif
 
 #include <fstream>
 #include <stdexcept>
@@ -47,30 +42,41 @@
 #include <ctime>
 #include <cstdio>
 
-int main( int argc, char** argv )
+/**
+ * Main entry point for tcl bindings generator.  Create a nessisary code
+ * tcl to access the functions.
+ *
+ * @returns	0 for success, 1 for incorrect number of args,
+ *		2 for some an exception.
+ */
+int
+main(int argc, char** argv)
 {
+	const string	progname = argv[0];
+
 	if ( argc != 3 ) {
-		cerr << "Usage: " << argv[0] << " <system-name> <file-to-generate>" << endl;
+		cerr << "Usage: " << progname << " <system-name> <file-to-generate>" << endl;
 		return 1;
 	}
 
+	const string	name = argv[1];
+	const string	ofile = argv[2];
+
 	try {
 		Systems systems;
 		build_systems( systems );
 
-		Systems::iterator system = systems.find( HSystem( argv[1] ) );
+		Systems::const_iterator system = systems.find(HSystem(name));
 		if ( system == systems.end() )
-			throw runtime_error( string( "System " ) + argv[1] + " is unknown" );
+			throw runtime_error("System " + name + " is unknown");
 
-		ofstream out( argv[2] );
+		ofstream out(ofile.c_str());
 		if ( !out )
-			throw runtime_error( string( "Unable to create " ) + argv[2] + ": " + ::strerror( errno ) );
+			throw runtime_error("Unable to create " + ofile +
+					    ": " + ::strerror(errno));
 
 		HSystem& s = const_cast<HSystem&>( *system );
-		s.gen_header( out );
-		s.gen_classes_interfaces( out );
-		s.gen_register_command_access( out );
-		s.gen_footer( out );
+		s.gen_file(out);
 	}
 	catch ( exception& err ) {
 		cerr << "Error: " << err.what() << endl;
@@ -81,7 +87,8 @@
 
 } /* main */
 
-void HSystem::gen_header( ostream& out )
+void
+HSystem::gen_header(ostream& out) const
 {
 	time_t t = time( 0 );
 	out << "/*" << endl;
@@ -110,7 +117,8 @@
 
 } /* HSystem::gen_header */
 
-void HSystem::gen_class_header( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void
+HSystem::gen_class_header(ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription)
 {
 	out << "class " << replace_chars( aClassDescription->name, ':', '_' ) << "Access : ";
 	if ( aClassDescription->parents[0] ) {
@@ -129,7 +137,8 @@
 
 } /* HSystem::gen_class_header */
 
-void HSystem::gen_callback_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void
+HSystem::gen_callback_interfaces(ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription)
 {
 	if ( aClassDescription->has_callbacks() ) {
 		out << "	virtual void activate_callback( Tcl_Interp* interp, Tcl_Obj* aCommand, Tcl_Obj* aUserData, Tcl_Obj* aArg, LanguageInterface::SpecificCallbackData& aSpecificCallbackData )\n"
@@ -170,7 +179,8 @@
 
 } /* HSystem::gen_callback_interfaces */
 
-void HSystem::gen_dynamic_methods_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void
+HSystem::gen_dynamic_methods_interfaces(ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription)
 {
 	out << "	static int methodCommand( ClientData obj, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[] )\n"
 	<< "		{\n"
@@ -347,7 +357,8 @@
 
 } /* HSystem::gen_dynamic_methods_interfaces */
 
-void HSystem::gen_static_method_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription )
+void
+HSystem::gen_static_method_interfaces( ostream& out, const LanguageInterface::Object::ClassDescription* aClassDescription)
 {
 	if ( aClassDescription->staticMethods() > 0 ) {
 		out << "  public:\n";
@@ -412,26 +423,27 @@
 
 } /* HSystem::gen_static_method_interfaces */
 
-void HSystem::gen_classes_interfaces( ostream& out )
+void
+HSystem::gen_classes_interfaces(ostream& out)
 {
 	for ( Descriptions::const_iterator di = descriptions.begin(); di != descriptions.end(); ++di ) {
-		cout << (*di)->name << endl;
+		const char	*name = (*di)->name;
+
+		cout << name << endl;
 		gen_class_header( out, *di );
 		gen_dynamic_methods_interfaces( out, *di );
 		gen_static_method_interfaces( out, *di );
 		gen_callback_interfaces( out, *di );
-		out << "}; /* class " << replace_chars( (*di)->name, ':', '_' ) << "Access */\n";
-
+		out << "}; /* class " << replace_chars(name, ':', '_') << "Access */\n";
 		out << endl;
 		out << endl;
 
-		commandAccessToRegister.push_back( (*di)->name );
+		commandAccessToRegister.push_back(name);
 	}
-
-} /* HSystem::gen_dynamic_methods_interfaces */
+} /* HSystem::gen_classes_interfaces */
 
-
-void HSystem::gen_register_command_access( ostream& out )
+void
+HSystem::gen_register_command_access(ostream& out)
 {
 	out << "void register_command_access_tcl()\n"
 	<< "{\n";
@@ -455,7 +467,8 @@
 } /* HSystem::gen_register_command_access */
 
 
-void HSystem::gen_footer( ostream& out )
+void
+HSystem::gen_footer(ostream& out) const
 {
 	out << "/* end */" << endl;
 	out << endl;
@@ -463,7 +476,8 @@
 } /* HSystem::gen_footer */
 
 
-string HSystem::gen_result_to_obj( LanguageInterface::Object::MethodDescription::Value t )
+string
+HSystem::gen_result_to_obj(LanguageInterface::Object::MethodDescription::Value t)
 {
 	switch ( (LanguageInterface::Object::MethodDescription::ValueType)t ) {
 	case LanguageInterface::Object::MethodDescription::vtVoid:
@@ -500,7 +514,8 @@
 } /* HSystem::gen_result_to_obj */
 
 
-string HSystem::gen_method_argument( LanguageInterface::Object::MethodDescription::Value t, int argno, int method_argno, bool last_arg_in_set_method )
+string
+HSystem::gen_method_argument(LanguageInterface::Object::MethodDescription::Value t, int argno, int method_argno, bool last_arg_in_set_method)
 {
 	string result;
 	if ( t.optional() && t != LanguageInterface::Object::MethodDescription::vtList && t != LanguageInterface::Object::MethodDescription::vtListRef && t != LanguageInterface::Object::MethodDescription::vtListPtr && !last_arg_in_set_method ) {
@@ -559,3 +574,4 @@
 	return(result);
 
 } /* HSystem::gen_method_argument */
+

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-libh" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?hfbscp6w81.fsf>