Permalink
Browse files

Replace C-strings with std::string and GLUI_String

  • Loading branch information...
nigels-com committed Jun 29, 2017
1 parent 027656a commit 936b3d7e6a42c6eab0eecc191861b0a98fa7fc30
View
@@ -508,9 +508,9 @@ void vec3::set(float x, float y, float z) // set vector
n[VZ] = z;
}
void vec3::print(FILE *file, const char *name) const // print vector to a file
void vec3::print(FILE *file, const std::string &name) const // print vector to a file
{
fprintf( file, "%s: <%f, %f, %f>\n", name, n[VX], n[VY], n[VZ] );
fprintf( file, "%s: <%f, %f, %f>\n", name.c_str(), n[VX], n[VY], n[VZ] );
}
// FRIENDS
@@ -781,9 +781,9 @@ vec4 &vec4::apply(V_FCT_PTR fct)
return *this;
}
void vec4::print(FILE *file, const char *name) const // print vector to a file
void vec4::print(FILE *file, const std::string &name) const // print vector to a file
{
fprintf( file, "%s: <%f, %f, %f, %f>\n", name, n[VX], n[VY], n[VZ], n[VW]);
fprintf( file, "%s: <%f, %f, %f, %f>\n", name.c_str(), n[VX], n[VY], n[VZ], n[VW]);
}
void vec4::set(float x, float y, float z, float a)
@@ -1168,11 +1168,11 @@ void swap(mat3 &a, mat3 &b)
b = tmp;
}
void mat3::print(FILE *file, const char *name) const
void mat3::print(FILE *file, const std::string &name) const
{
int i, j;
fprintf( stderr, "%s:\n", name );
fprintf( stderr, "%s:\n", name.c_str() );
for( i = 0; i < 3; i++ )
{
@@ -1348,11 +1348,11 @@ mat4 &mat4::apply(V_FCT_PTR fct)
return *this;
}
void mat4::print(FILE *file, const char *name) const
void mat4::print(FILE *file, const std::string &name) const
{
int i, j;
fprintf( stderr, "%s:\n", name );
fprintf( stderr, "%s:\n", name.c_str() );
for( i = 0; i < 4; i++ )
{
View
@@ -79,6 +79,8 @@
#ifndef GLUI_ALGEBRA3_H
#define GLUI_ALGEBRA3_H
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@@ -212,7 +214,7 @@ class vec3
vec3& apply(V_FCT_PTR fct); // apply a func. to each component
void set(float x, float y, float z); // set vector
void print(FILE *file, const char *name) const; // print vector to a file
void print(FILE *file, const std::string &name) const; // print vector to a file
float &operator [] (int i); // indexing
@@ -287,7 +289,7 @@ class vec4
vec4 &apply(V_FCT_PTR fct); // apply a func. to each component
vec4 &homogenize();
void print(FILE *file, const char *name) const; // print vector to a file
void print(FILE *file, const std::string &name) const; // print vector to a file
void set(float x, float y, float z, float a);
@@ -354,7 +356,7 @@ class mat3
mat3 inverse() const; // inverse
mat3 &apply(V_FCT_PTR fct); // apply a func. to each element
void print(FILE *file, const char *name ) const; // print matrix to a file
void print(FILE *file, const std::string &name ) const; // print matrix to a file
void set(const vec3 &v0, const vec3 &v1, const vec3 &v2);
@@ -421,7 +423,7 @@ class mat4
mat4 inverse() const; // inverse
mat4 &apply(V_FCT_PTR fct); // apply a func. to each element
void print(FILE *file, const char *name) const; // print matrix to a file
void print(FILE *file, const std::string &name) const; // print matrix to a file
vec4 &operator [] (int i); // indexing
const vec4 &operator [] (int i) const; // indexing
View
@@ -54,7 +54,7 @@ void control_cb( int control )
printf( " checkbox: %d\n", checkbox->get_int_val() );
printf( " spinner: %d\n", spinner->get_int_val() );
printf( " radio group: %d\n", radio->get_int_val() );
printf( " text: %s\n", edittext->get_text() );
printf( " text: %s\n", edittext->get_text().c_str() );
}
View
@@ -142,7 +142,7 @@ void pointer_cb( GLUI_Control* control )
}
else if ( control == cmd_line ) {
/*** User typed text into the 'command line' window ***/
printf( "Command (%d): %s\n", counter, cmd_line->get_text() );
printf( "Command (%d): %s\n", counter, cmd_line->get_text().c_str() );
std::string text = cmd_line->get_text();
if (text =="exit" || text == "quit")
exit(0);
View
@@ -122,7 +122,7 @@ void GLUI_CB::operator()(GLUI_Control*ctrl) const
/************************************************ GLUI::GLUI() **********/
int GLUI::init( const char *text, long flags, int x, int y, int parent_window )
int GLUI::init( const GLUI_String &text, long flags, int x, int y, int parent_window )
{
int old_glut_window;
@@ -179,13 +179,13 @@ int GLUI::init( const char *text, long flags, int x, int y, int parent_window )
/**************************** GLUI_Main::create_standalone_window() ********/
void GLUI_Main::create_standalone_window( const char *name, int x, int y )
void GLUI_Main::create_standalone_window( const GLUI_String &name, int x, int y )
{
glutInitWindowSize( 100, 100 );
if ( x >= 0 OR y >= 0 )
glutInitWindowPosition( x, y );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glut_window_id = glutCreateWindow( name );
glut_window_id = glutCreateWindow( name.c_str() );
}
@@ -498,7 +498,7 @@ GLUI_Master_Object::~GLUI_Master_Object()
/*********************************** GLUI_Master_Object::create_glui() ******/
GLUI *GLUI_Master_Object::create_glui( const char *name, long flags,int x,int y )
GLUI *GLUI_Master_Object::create_glui( const GLUI_String &name, long flags,int x,int y )
{
GLUI *new_glui = new GLUI;
new_glui->init( name, flags, x, y, -1 );
@@ -615,40 +615,24 @@ void GLUI_Main::display()
}
}
/*************************************** _glutBitmapWidthString() **********/
int _glutBitmapWidthString( void *font, const char *s )
int _glutBitmapWidthString( void *font, const GLUI_String &s )
{
const char *p = s;
int width = 0;
while( *p != '\0' ) {
width += glutBitmapWidth( font, *p );
p++;
}
for (auto i : s) width += glutBitmapWidth( font, i );
return width;
}
/************************************ _glutBitmapString *********************/
/* Displays the contents of a string using GLUT's bitmap character function */
/* Does not handle newlines */
void _glutBitmapString( void *font, const char *s )
void _glutBitmapString( void *font, const GLUI_String &s )
{
const char *p = s;
while( *p != '\0' ) {
glutBitmapCharacter( font, *p );
p++;
}
for (auto i : s) glutBitmapCharacter( font, i );
}
/****************************** GLUI_Main::reshape() **************/
void GLUI_Main::reshape( int reshape_w, int reshape_h )
Oops, something went wrong.

0 comments on commit 936b3d7

Please sign in to comment.