Go to the source code of this file.
Data Structures | |
struct | s_scanner |
Represents a scanner. More... | |
Typedefs | |
typedef enum e_token | t_token |
typedef struct s_scanner | t_scanner |
Represents a scanner. More... | |
Enumerations | |
enum | e_token { TOKEN_AMBIENT_LIGHT , TOKEN_CAMERA , TOKEN_LIGHT , TOKEN_SPHERE , TOKEN_PLANE , TOKEN_CYLINDER , TOKEN_CONE , TOKEN_NEWLINE , TOKEN_COMMENT , TOKEN_ERROR , TOKEN_COUNT } |
Functions | |
void | init_scanner (t_scanner *scanner, const char *source) |
Scanner. More... | |
t_bool | scan_integer (t_scanner *scanner) |
Identify if input character sequence forms an integer. More... | |
t_bool | scan_double (t_scanner *scanner) |
Identify if input character sequence forms a double number. More... | |
t_bool | scan_comma (t_scanner *scanner) |
Verify presence of a comma in the input. More... | |
t_bool | scan_newline (t_scanner *scanner) |
Verify presence of a newline in the input. More... | |
t_token | parse_type (t_scanner *scanner) |
Parse types. More... | |
void | advance (t_scanner *scanner) |
Scanner utils. More... | |
void | skip_whitespace (t_scanner *scanner) |
Skip all encountered whitespace characters. More... | |
int | is_sign (int c) |
Check if character is a sign. More... | |
void | save_position (t_scanner *scanner) |
Saves the current position of the scanner for later restoration and synchronization with the parser. More... | |
void | sync_position (t_scanner *scanner) |
Synchronizes the scanner with the parser by restoring its position to a previously saved position. More... | |
t_bool | parse (char *filename, t_scene *scene) |
Parse. More... | |
t_bool | check_extension (const char *filename, const char *extension) |
Check if a filename has a specified extension. More... | |
t_bool | parse_element (t_scanner *scanner, t_scene *scene, int totals[]) |
Parse element. More... | |
t_bool | parse_comment (t_scanner *scanner) |
Parse comments. More... | |
void | add_object_to_world (t_shape *shape, t_world *world) |
Add a shape to the world. More... | |
void | add_light_to_world (t_light *light, t_world *world) |
Add a light source to the world. More... | |
t_bool | parse_double (t_scanner *scanner, double *result) |
Parse basic. More... | |
t_bool | parse_light_ratio (t_scanner *scanner, double *light) |
Parse the light ratio from the input. More... | |
t_bool | parse_field_of_view (t_scanner *scanner, int *fov) |
Convert field of view from input and store it in fov . More... | |
t_bool | parse_dimension (t_scanner *scanner, double *dimension) |
Convert dimension from input and store it in dimension . More... | |
t_bool | parse_color (t_scanner *scanner, t_color *result) |
Parse grouped. More... | |
t_bool | parse_position (t_scanner *scanner, t_point *position) |
Convert a position from the input and store it in position . More... | |
t_bool | parse_direction (t_scanner *scanner, t_vector *direction) |
Convert a direction from the input and store it in direction . More... | |
t_bool | parse_pattern (t_scanner *scanner, t_shape *shape) |
Parse a pattern from the input and assign it to a shape. More... | |
t_bool | parse_ambient_light (t_scanner *scanner, t_scene *scene) |
Parse ambient. More... | |
t_bool | parse_camera (t_scanner *scanner, t_scene *scene) |
Convert camera from input and add to scene. More... | |
t_bool | parse_light (t_scanner *scanner, t_scene *scene) |
Convert light point from input and add to scene. More... | |
t_bool | parse_sphere (t_scanner *scanner, t_scene *scene) |
Parse shapes. More... | |
t_bool | parse_plane (t_scanner *scanner, t_scene *scene) |
Convert a plane from the input and add it to the scene. More... | |
t_bool | parse_cylinder (t_scanner *scanner, t_scene *scene) |
Convert a cylinder from the input and add it to the scene. More... | |
t_bool | parse_cone (t_scanner *scanner, t_scene *scene) |
Convert a cone from the input and add it to the scene. More... | |
t_bool | report_error (t_scanner *scanner) |
Parse utils. More... | |
t_bool | validate_range (double value, double start, double end) |
Validate if a number is within a certain range. More... | |
int | get_error_column (t_scanner *scanner) |
Get the column where an error occurred. More... | |
void | set_error_state (t_scanner *scanner, const char *error_message) |
Determine the error message based on the state of the scanner. More... | |
t_bool | parse_texture (t_scanner *scanner, t_shape *shape) |
Parse textures. More... | |
Represents a scanner.
The scanner structure is used for scanning and tokenizing input text.
The scanning process is performed using two pointers, consume
and current
, which need to be kept separate. While current
reads from the input and checks if the character sequence is correct, consume
remains pointing to the beginning of the portion being verified. This eliminates the need to split the input into pieces and allows for precise identification of the section of input that needs to be converted.
line | Stores the line number being read. |
start | A pointer to the first character of the line. |
consume | A pointer passed to the number conversion functions. |
current | A pointer used for reading character by character. |
message | A pointer to the current error message, if any. |
Add a light source to the world.
light | Pointer to the light source to be added. |
world | Pointer to the world. |
Add a shape to the world.
shape | Pointer to the shape to be added. |
world | Pointer to the world. |
void advance | ( | t_scanner * | scanner | ) |
Scanner utils.
Advance the current
pointer to the next character.
This function advances the current pointer of the scanner to the next character in the input.
scanner | Pointer to the scanner. |
t_bool check_extension | ( | const char * | filename, |
const char * | extension | ||
) |
Check if a filename has a specified extension.
This function checks whether a given filename has a specified extension. It compares the extension of the filename with the provided extension parameter. The extension should be passed without the leading dot (e.g., "png" instead of ".png"). If the filename has the same extension, the function returns true; otherwise, it returns false.
filename | The filename to check. |
extension | The desired extension to compare with (without the leading dot). |
int get_error_column | ( | t_scanner * | scanner | ) |
Get the column where an error occurred.
This function returns the column number where an error occurred during scanning. It calculates the column number by subtracting the starting pointer of the scanner (scanner->start) from the current pointer (scanner->current). The result represents the offset in characters between the start of the input and the current position where the error occurred.
scanner | Pointer to the scanner. |
void init_scanner | ( | t_scanner * | scanner, |
const char * | source | ||
) |
Scanner.
Initializes a scanner with the provided source.
This function initializes a scanner structure with the given source.
scanner | A pointer to the scanner structure to be initialized. |
source | The source to be scanned and tokenized. |
int is_sign | ( | int | c | ) |
Check if character is a sign.
Checks if given character represents a sign (positive or negative).
c | Character to be checked. |
t_bool parse | ( | char * | filename, |
t_scene * | scene | ||
) |
Parse.
Open and read a file, assigning found elements to the scene.
This function opens and reads a file specified by the filename. It parses the content of the file, assigning each found element to the given scene.
filename | Name of the file to open and read. |
scene | Pointer to the scene object. |
Parse ambient.
Convert ambient light from input and add to scene.
scanner | Pointer to the scanner object. |
scene | Pointer to the scene to add ambient light. |
Convert camera from input and add to scene.
scanner | Pointer to the scanner object. |
scene | Pointer to the scene to add camera. |
Parse grouped.
Convert a color from the input and store it in result
.
This function converts a color from the input by analyzing the scanned sequence in the given scanner and stores it in the memory location pointed to by result
. It verifies if each color channel (red, green, and blue) is between 0 and 255. If there is an error during conversion or if any channel value is out of range, the scanner is configured with the appropriate error message.
scanner | Pointer to the scanner. |
result | Pointer to the memory location where the parsed color will be stored. |
t_bool parse_comment | ( | t_scanner * | scanner | ) |
Parse comments.
scanner | Pointer to the scanner. |
Convert a cone from the input and add it to the scene.
This function converts a cone from the input by analyzing the scanned sequence in the given scanner and adds it to the scene. It uses the provided scanner to parse the necessary properties of the cone such as its position, direction, diameter, height, color, pattern, and any additional attributes.
scanner | Pointer to the scanner. |
scene | Pointer to the scene where the cone will be added. |
Convert a cylinder from the input and add it to the scene.
This function converts a cylinder from the input by analyzing the scanned sequence in the given scanner and adds it to the scene. It uses the provided scanner to parse the necessary properties of the cylinder such as its position, direction, diameter, height, color, pattern, and any additional attributes.
scanner | Pointer to the scanner. |
scene | Pointer to the scene where the cylinder will be added. |
t_bool parse_dimension | ( | t_scanner * | scanner, |
double * | dimension | ||
) |
Convert dimension from input and store it in dimension
.
This function converts the dimension from the input by analyzing the scanned sequence in the given scanner and stores it in the memory location pointed to by dimension
. It verifies if the dimension is a positive number. If there is an error during conversion or if the value is not positive, the scanner is configured with the appropriate error message.
scanner | Pointer to the scanner. |
dimension | Pointer to the memory location where the parsed dimension will be stored. |
Convert a direction from the input and store it in direction
.
This function converts a direction vector from the input by analyzing the scanned sequence in the given scanner and stores it in the memory location pointed to by direction
. It verifies if each component of the vector is between -1 and 1. If there is an error during conversion or if any component value is out of range, the scanner is configured with the appropriate error message.
scanner | Pointer to the scanner object. |
direction | Pointer to the memory location where the parsed direction will be stored. |
t_bool parse_double | ( | t_scanner * | scanner, |
double * | result | ||
) |
Parse basic.
Convert double from input and store in result.
scanner | Pointer to the scanner. |
result | Pointer to store the parsed double. |
Parse element.
Parses and processes an element from the input.
This function parses and processes an element from the input by analyzing the scanned sequence in the given scanner. It also updates the totals array to keep track of the number of elements read from the input.
scanner | A pointer to the scanner structure. |
scene | A pointer to the scene structure. |
totals | An array to store the count of elements read from the input. |
t_bool parse_field_of_view | ( | t_scanner * | scanner, |
int * | fov | ||
) |
Convert field of view from input and store it in fov
.
This function converts the field of view from the input by analyzing the scanned sequence in the given scanner and stores it in the memory location pointed to by fov
. It verifies if the field of view is within the range of 0 to 180 degrees. If there is an error during conversion or if the value is outside the valid range, the scanner is configured with the appropriate error message.
scanner | Pointer to the scanner. |
fov | Pointer to the memory location where the parsed field of view will be stored. |
Convert light point from input and add to scene.
scanner | Pointer to the scanner object. |
scene | Pointer to the scene to add light point. |
t_bool parse_light_ratio | ( | t_scanner * | scanner, |
double * | light | ||
) |
Parse the light ratio from the input.
This function parses the light ratio from the input by analyzing the scanned sequence in the given scanner. It verifies if the number is within the range [0, 1]. If there is an error during parsing or if the number is outside the valid range, the scanner is configured with the appropriate error message.
scanner | Pointer to the scanner of type t_scanner. |
light | Pointer to the memory location where the parsed light ratio will be stored. |
Parse a pattern from the input and assign it to a shape.
scanner | Pointer to the scanner object. |
shape | Pointer to the shape to which the parsed pattern will be assigned. |
Convert a plane from the input and add it to the scene.
This function converts a plane from the input by analyzing the scanned sequence in the given scanner and adds it to the scene. It uses the provided scanner to parse the necessary properties of the plane such as its position, direction, color, pattern, and any additional attributes.
scanner | Pointer to the scanner. |
scene | Pointer to the scene where the plane will be added. |
Convert a position from the input and store it in position
.
scanner | Pointer to the scanner object. |
position | Pointer to the memory location where the parsed position will be stored. |
Parse shapes.
Convert a sphere from the input and add it to the scene.
This function converts a sphere from the input by analyzing the scanned sequence in the given scanner and adds it to the scene. It uses the provided scanner to parse the necessary properties of the sphere such as its position, radius, color, pattern, and any additional attributes.
scanner | Pointer to the scanner. |
scene | Pointer to the scene where the sphere will be added. |
Parse textures.
Validate and load a texture file into a UV map and assign it to the shape.
This function validates the integrity of the texture file to be scanned, loads the file into a UV map, and assigns it to the specified shape. The texture file is loaded into a UV map, which represents the mapping of the texture coordinates onto the surface of the shape. The UV map allows for accurate and realistic texture mapping, enhancing the visual appearance of the shape.
scanner | Pointer to the scanner. |
shape | Pointer to the shape to which the texture will be assigned. |
t_token parse_type | ( | t_scanner * | scanner | ) |
Parse types.
Identify token characterizing analysis type in a line.
Determines the token representing the analysis type in a line of the input.
scanner | Pointer to scanner object. |
t_bool report_error | ( | t_scanner * | scanner | ) |
Parse utils.
Display an error message based on the state of the scanner.
scanner | Pointer to the scanner. |
void save_position | ( | t_scanner * | scanner | ) |
Saves the current position of the scanner for later restoration and synchronization with the parser.
This function takes a pointer to a scanner object and saves the current position of the scanner in the sync pointer of the scanner object. The saved position can be used later to restore the scanner to its current position and synchronize it with the parser.
scanner | A pointer to a scanner object. |
t_bool scan_comma | ( | t_scanner * | scanner | ) |
Verify presence of a comma in the input.
This function verifies if there is a comma character in the input scanner.
scanner | Pointer to the scanner. |
t_bool scan_double | ( | t_scanner * | scanner | ) |
Identify if input character sequence forms a double number.
This function checks if the character sequence in the input scanner represents a valid double number.
scanner | Pointer to the scanner. |
t_bool scan_integer | ( | t_scanner * | scanner | ) |
Identify if input character sequence forms an integer.
This function determines whether the character sequence in the input forms a valid integer.
scanner | Pointer to the scanner. |
t_bool scan_newline | ( | t_scanner * | scanner | ) |
Verify presence of a newline in the input.
This function verifies if there is a newline character in the given scanner.
scanner | Pointer to the scanner. |
void set_error_state | ( | t_scanner * | scanner, |
const char * | error_message | ||
) |
Determine the error message based on the state of the scanner.
This function sets the error state of the scanner by assigning the provided error message to the scanner's message field. It also resets the current position in the scanner's input to the consume position, effectively rewinding the scanner to a specific location.
scanner | Pointer to the scanner object. |
error_message | The error message to be assigned to the scanner. |
void skip_whitespace | ( | t_scanner * | scanner | ) |
Skip all encountered whitespace characters.
This function skips all whitespace characters encountered by advancing the current pointer of the scanner past them in the input.
scanner | Pointer to the scanner. |
void sync_position | ( | t_scanner * | scanner | ) |
Synchronizes the scanner with the parser by restoring its position to a previously saved position.
This function takes a pointer to a scanner object and restores the scanner to the saved position in the sync pointer of the scanner object, synchronizing it with the parser.
scanner | A pointer to a scanner object. |
t_bool validate_range | ( | double | value, |
double | start, | ||
double | end | ||
) |
Validate if a number is within a certain range.
This function checks if the given value is within the specified range, inclusive.
value | The value to be validated. |
start | The start of the range. |
end | The end of the range. |