Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/interrogate/parameterRemapEnumToInt.cxx

Go to the documentation of this file.
00001 // Filename: parameterRemapEnumToInt.cxx
00002 // Created by:  drose (04Aug00)
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 "parameterRemapEnumToInt.h"
00020 #include "interrogate.h"
00021 
00022 #include <cppSimpleType.h>
00023 #include <cppConstType.h>
00024 #include <cppPointerType.h>
00025 #include <cppReferenceType.h>
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: ParameterRemapEnumToInt::Constructor
00029 //       Access: Public
00030 //  Description:
00031 ////////////////////////////////////////////////////////////////////
00032 ParameterRemapEnumToInt::
00033 ParameterRemapEnumToInt(CPPType *orig_type) :
00034   ParameterRemap(orig_type)
00035 {
00036   _new_type = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int));
00037   _enum_type = unwrap_type(_orig_type);
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: ParameterRemapEnumToInt::pass_parameter
00042 //       Access: Public, Virtual
00043 //  Description: Outputs an expression that converts the indicated
00044 //               variable from the new type to the original type, for
00045 //               passing into the actual C++ function.
00046 ////////////////////////////////////////////////////////////////////
00047 void ParameterRemapEnumToInt::
00048 pass_parameter(ostream &out, const string &variable_name) {
00049   out << "(" << _enum_type->get_local_name(&parser) << ")" << variable_name;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: ParameterRemapEnumToInt::get_return_expr
00054 //       Access: Public, Virtual
00055 //  Description: Returns an expression that evalutes to the
00056 //               appropriate value type for returning from the
00057 //               function, given an expression of the original type.
00058 ////////////////////////////////////////////////////////////////////
00059 string ParameterRemapEnumToInt::
00060 get_return_expr(const string &expression) {
00061   return "(int)(" + expression + ")";
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: ParameterRemapEnumToInt::unwrap_type
00066 //       Access: Private
00067 //  Description: Recursively walks through the type definition,
00068 //               and finds the enum definition under all the wrappers.
00069 ////////////////////////////////////////////////////////////////////
00070 CPPType *ParameterRemapEnumToInt::
00071 unwrap_type(CPPType *source_type) const {
00072   switch (source_type->get_subtype()) {
00073   case CPPDeclaration::ST_const:
00074     return unwrap_type(source_type->as_const_type()->_wrapped_around);
00075 
00076   case CPPDeclaration::ST_reference:
00077     return unwrap_type(source_type->as_reference_type()->_pointing_at);
00078 
00079   case CPPDeclaration::ST_pointer:
00080     return unwrap_type(source_type->as_pointer_type()->_pointing_at);
00081 
00082   default:
00083     return source_type;
00084   }
00085 }

Generated on Thu May 1 22:13:03 2003 for DTool by doxygen1.3