00001 // Filename: functionWriters.cxx 00002 // Created by: drose (14Sep01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "functionWriters.h" 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: FunctionWriters::Constructor 00023 // Access: Public 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 FunctionWriters:: 00027 FunctionWriters() { 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: FunctionWriters::Destructor 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 FunctionWriters:: 00036 ~FunctionWriters() { 00037 Writers::iterator wi; 00038 for (wi = _writers.begin(); wi != _writers.end(); ++wi) { 00039 delete (*wi); 00040 } 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: FunctionWriters::add_writer 00045 // Access: Public 00046 // Description: Adds the indicated FunctionWriter to the set of 00047 // functions to be written, unless there is already a 00048 // matching FunctionWriter. 00049 // 00050 // The return value is the FunctionWriter pointer that 00051 // was added to the set, which may be the same pointer 00052 // or a previously-allocated (but equivalent) pointer. 00053 //////////////////////////////////////////////////////////////////// 00054 FunctionWriter *FunctionWriters:: 00055 add_writer(FunctionWriter *writer) { 00056 pair<Writers::iterator, bool> result = _writers.insert(writer); 00057 if (!result.second) { 00058 // Already there; delete the pointer. 00059 delete writer; 00060 } 00061 00062 // Return the pointer that is in the set. 00063 return *result.first; 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: FunctionWriters::write_prototypes 00068 // Access: Public 00069 // Description: Generates prototypes for all of the functions. 00070 //////////////////////////////////////////////////////////////////// 00071 void FunctionWriters:: 00072 write_prototypes(ostream &out) { 00073 Writers::iterator wi; 00074 for (wi = _writers.begin(); wi != _writers.end(); ++wi) { 00075 FunctionWriter *writer = (*wi); 00076 writer->write_prototype(out); 00077 } 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: FunctionWriters::write_code 00082 // Access: Public 00083 // Description: Generates all of the functions. 00084 //////////////////////////////////////////////////////////////////// 00085 void FunctionWriters:: 00086 write_code(ostream &out) { 00087 Writers::iterator wi; 00088 for (wi = _writers.begin(); wi != _writers.end(); ++wi) { 00089 FunctionWriter *writer = (*wi); 00090 writer->write_code(out); 00091 } 00092 }