Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    Conditional Statements - examples of use -
Deutsch Deutsch

Home
- POV-Ray Tutorial

  - Conditional
    Statements

  Branching
    #if(...)... #else ... #end
    - in loops
    - in macros
    - in animations
    - turning on/off of parts
    #switch(...) #case .. #end
    - selection by tables

  Check for Existence
    #ifdef(...) #ifndef(...)
    >Check for include files
    - Defaults in include files

  Loops
 Prechecked, Postchecked,
 Count-controlled, Early-Exit
    #while(...)... #end
    #for(...)... #end
    - Samples:
    - Loops with POV-Ray
    - Loops, Sine, Cosine
    - Random with POV-Ray
                                       

Check for Existance - Check if an Include File is loaded

Two examples for the use of "#ifndef" with include files:
1. Avoiding multiple loading of an include file:
By declaring an according globalen variable in each include file,
(here: MyIncludeFile_Inc_Temp, if the include file name is MyIncludeFile.inc)
we can check by "#ifndef" if this include file was loaded before. In this case the hole content can be passed over because its content is already known.
2. Making sure that necessary include files for an include file are loaded and not will be loaded twice:
The following technique can be used to integrate those include files, which are declaring an according global variable (MyIncludeFile_Inc_Temp) like explained here above.
In include files which need another include file, by a query on the existens of the according global variable with "#ifndef", we can achieve that the needed other include file will be loaded if the scene file didn't load this necessary file before.
In addition this technique avoids a multiple loading of the according include file if it was loaded befor by the scene file or by other include files.

Avoiding multiple loading of an include file:
// include file "MyIncludeFile.inc"
#ifndef( MyIncludeFile_inc_Temp )
#declare MyIncludeFile_Inc_Temp = version;
#version 3.5;
//----------------------------------------

body of include file


//----------------------------------------
#version MyIncludeFile_Inc_Temp;
#end // end of "#ifndef( ... )"
//-------------------- end of include file
Making sure that necessary include files are loaded and avoiding multiple loading of these include files:

//--------------------------//
#ifndef(  Shapes_Inc_Temp)
#include "shapes.inc"
#end
//--------------------------//

top
© Friedrich A. Lohmüller, 2010
homepage:http://www.f-lohmueller.de