Added 'const' in declarations

This commit is contained in:
Kolan Sh 2012-05-01 11:30:29 +04:00
parent 2bf8698183
commit c03fdd01a7
6 changed files with 33 additions and 33 deletions

View File

@ -15,7 +15,7 @@ void ColoredSquare_constructor (ColoredSquare *this,
this->color = color;
}
void ColoredSquare_copy (ColoredSquare *to, ColoredSquare *from)
void ColoredSquare_copy (ColoredSquare *to, const ColoredSquare *from)
{
printf ("ColoredSquare_copy (%lu, %lu) called\n",
(unsigned long) to,
@ -24,7 +24,7 @@ void ColoredSquare_copy (ColoredSquare *to, ColoredSquare *from)
to->color = from->color;
}
ColoredSquare* ColoredSquare_clone (ColoredSquare *this)
ColoredSquare* ColoredSquare_clone (const ColoredSquare *this)
{
ColoredSquare *csquare = ColoredSquare_new (0.0, 0);
printf ("ColoredSquare_clone (%lu) called\n",
@ -37,7 +37,7 @@ ColoredSquare* ColoredSquare_clone (ColoredSquare *this)
return csquare;
}
const char* ColoredSquare_type (ColoredSquare *this)
const char* ColoredSquare_type (const ColoredSquare *this)
{
static const char *csquare_type_str = "ColoredSquare";
printf ("ColoredSquare_type (%lu) called\n",
@ -48,7 +48,7 @@ const char* ColoredSquare_type (ColoredSquare *this)
return csquare_type_str;
}
void ColoredSquare_draw (ColoredSquare *this)
void ColoredSquare_draw (const ColoredSquare *this)
{
printf ("ColoredSquare_draw (%lu) called\n",
(unsigned long) this);
@ -74,12 +74,12 @@ ColoredSquare* ColoredSquare_new (double a, int color)
{
{
{
(void* (*) (void *)) ColoredSquare_clone,
(void* (*) (const void *)) ColoredSquare_clone,
(void (*) (void *)) Square_destroy
},
(const char* (*) (Figure *)) ColoredSquare_type,
(void (*) (Figure *)) ColoredSquare_draw,
(double (*) (Figure *)) Square_area
(const char* (*) (const Figure *)) ColoredSquare_type,
(void (*) (const Figure *)) ColoredSquare_draw,
(double (*) (const Figure *)) Square_area
},
Square_resize,
Square_diag_length

View File

@ -24,10 +24,10 @@ typedef struct ColoredSquare_interface
void ColoredSquare_constructor (struct ColoredSquare *this,
double a,
int color);
void ColoredSquare_copy (struct ColoredSquare *to, struct ColoredSquare *from);
struct ColoredSquare* ColoredSquare_clone (struct ColoredSquare *this);
const char* ColoredSquare_type (struct ColoredSquare *this);
void ColoredSquare_draw (struct ColoredSquare *this);
void ColoredSquare_copy (struct ColoredSquare *to, const struct ColoredSquare *from);
struct ColoredSquare* ColoredSquare_clone (const struct ColoredSquare *this);
const char* ColoredSquare_type (const struct ColoredSquare *this);
void ColoredSquare_draw (const struct ColoredSquare *this);
void ColoredSquare_set_color (struct ColoredSquare *this, int color);
/* public */

View File

@ -9,9 +9,9 @@ typedef struct Figure_interface
{
Object_interface;
const char* (*type) (struct Figure *this);
void (*draw) (struct Figure *this);
double (*area) (struct Figure *this);
const char* (*type) (const struct Figure *this);
void (*draw) (const struct Figure *this);
double (*area) (const struct Figure *this);
} Figure_interface;

View File

@ -3,7 +3,7 @@
typedef struct Object_interface
{
void* (*clone) (void *this);
void* (*clone) (const void *this);
void (*destroy) (void *this);
} Object_interface;

View File

@ -17,7 +17,7 @@ void Square_destructor (Square *this)
(unsigned long) this);
}
void Square_copy (Square *to, Square *from)
void Square_copy (Square *to, const Square *from)
{
printf ("Square_copy (%lu, %lu) called\n",
(unsigned long) to,
@ -25,7 +25,7 @@ void Square_copy (Square *to, Square *from)
to->a = from->a;
}
Square* Square_clone (Square *this)
Square* Square_clone (const Square *this)
{
Square *square = Square_new (0.0);
printf ("Square_clone (%lu) called\n",
@ -45,7 +45,7 @@ void Square_destroy (Square *this)
free (this);
}
const char* Square_type (Square *this)
const char* Square_type (const Square *this)
{
static const char *square_type_str = "Square";
printf ("Square_type (%lu) called\n",
@ -57,7 +57,7 @@ const char* Square_type (Square *this)
return square_type_str;
}
void Square_draw (Square *this)
void Square_draw (const Square *this)
{
printf ("Square_draw (%lu) called\n",
(unsigned long) this);
@ -65,7 +65,7 @@ void Square_draw (Square *this)
this->a);
}
double Square_area (Square *this)
double Square_area (const Square *this)
{
double area = this->a * this->a;
printf ("Square_area (%lu) called\n",
@ -85,7 +85,7 @@ void Square_resize (Square *this, double a)
this->a = a;
}
double Square_diag_length (Square *this)
double Square_diag_length (const Square *this)
{
double diag_length = ((Square *)this)->a * 1.41421356;
@ -105,12 +105,12 @@ Square* Square_new (double a)
{
{
{
(void* (*) (void *)) Square_clone,
(void* (*) (const void *)) Square_clone,
(void (*) (void *)) Square_destroy
},
(const char* (*) (Figure *)) Square_type,
(void (*) (Figure *)) Square_draw,
(double (*) (Figure *)) Square_area
(const char* (*) (const Figure *)) Square_type,
(void (*) (const Figure *)) Square_draw,
(double (*) (const Figure *)) Square_area
},
Square_resize,
Square_diag_length

View File

@ -16,20 +16,20 @@ typedef struct Square_interface
Figure_interface;
void (*resize) (struct Square *this, double a);
double (*diag_length) (struct Square *this);
double (*diag_length) (const struct Square *this);
} Square_interface;
void Square_constructor (struct Square *this, double a);
void Square_destructor (struct Square *this);
void Square_copy (struct Square *to, struct Square *from);
struct Square* Square_clone (struct Square *this);
void Square_copy (struct Square *to, const struct Square *from);
struct Square* Square_clone (const struct Square *this);
void Square_destroy (struct Square *this);
const char* Square_type (struct Square *this);
void Square_draw (struct Square *this);
double Square_area (struct Square *this);
const char* Square_type (const struct Square *this);
void Square_draw (const struct Square *this);
double Square_area (const struct Square *this);
void Square_resize (struct Square *this, double a);
double Square_diag_length (struct Square *this);
double Square_diag_length (const struct Square *this);
/* public */
typedef struct Square