| 1 | /*************************************************************************** |
| 2 | propertymanager.h - description |
| 3 | ------------------- |
| 4 | begin : feb 06th, 2004 |
| 5 | copyright : (C) 2003-2010 by Duong Khang NGUYEN |
| 6 | email : neoneurone @ gmail com |
| 7 | |
| 8 | $Id: propertymanager.h 450 2010-11-21 19:11:43Z neoneurone $ |
| 9 | ***************************************************************************/ |
| 10 | |
| 11 | /*************************************************************************** |
| 12 | * * |
| 13 | * This program is free software; you can redistribute it and/or modify * |
| 14 | * it under the terms of the GNU General Public License as published by * |
| 15 | * the Free Software Foundation; either version 2 of the License, or * |
| 16 | * any later version. * |
| 17 | * * |
| 18 | ***************************************************************************/ |
| 19 | |
| 20 | #ifndef _OPENCITY_PROPERTYMANAGER_H_ |
| 21 | #define _OPENCITY_PROPERTYMANAGER_H_ 1 |
| 22 | |
| 23 | #include "main.h" |
| 24 | #include "conf.h" // For models' configuration files |
| 25 | |
| 26 | #include <vector> |
| 27 | |
| 28 | class Structure; |
| 29 | |
| 30 | |
| 31 | //======================================================================== |
| 32 | /** This manager handles specially the models' .conf files. When an instance is |
| 33 | created, it reads the "graphism.conf" file and load all the associated |
| 34 | models' .conf files for later use. If a .conf file is not found for a specific |
| 35 | model, the manager just silently ignores the problem. It's the programmer's |
| 36 | responsability to not query that .conf, otherwise, the manager will crash. |
| 37 | */ |
| 38 | class PropertyManager |
| 39 | { |
| 40 | public: |
| 41 | PropertyManager(); |
| 42 | ~PropertyManager(); |
| 43 | |
| 44 | |
| 45 | //======================================================================== |
| 46 | /** Returns the requested property of the structure |
| 47 | \param pCode The code of the requested property |
| 48 | \param sCode The structure code |
| 49 | \param pcStruct The pointer to the structure (optional) |
| 50 | \return The value of the requested property |
| 51 | \see enum.h for more details about the parameters |
| 52 | */ |
| 53 | const int |
| 54 | Get( |
| 55 | const OPENCITY_PROPERTY_CODE& pCode, |
| 56 | const OPENCITY_STRUCTURE_CODE& sCode, |
| 57 | const Structure* pcStruct = NULL ) const; |
| 58 | |
| 59 | |
| 60 | //======================================================================== |
| 61 | /** Return the _first_ level graphic code for the corresponding |
| 62 | structure code |
| 63 | \param scode The structure code of the structure that you want to |
| 64 | retrieve the graphic code. |
| 65 | \return The corresponding graphic code |
| 66 | */ |
| 67 | const OPENCITY_GRAPHIC_CODE |
| 68 | GetGC( |
| 69 | const OPENCITY_STRUCTURE_CODE scode ) const; |
| 70 | |
| 71 | |
| 72 | //======================================================================== |
| 73 | /** Return the structure type from its structure code. This is used |
| 74 | for serialization. |
| 75 | */ |
| 76 | const OPENCITY_STRUCTURE_TYPE |
| 77 | GetST( |
| 78 | const OPENCITY_STRUCTURE_CODE scode ) const; |
| 79 | |
| 80 | |
| 81 | //======================================================================== |
| 82 | /** Return the structure's "width, length, and height" parameter |
| 83 | \param gcode The graphic code of the structure that you want to retrieve |
| 84 | the properties |
| 85 | \param w Structure's width (OpenGL Ox) |
| 86 | \param l Structure's length (OpenGL Oz) |
| 87 | \param h Structure's height (OpenGL Oy) |
| 88 | \param defw, defl, defh contain the default values for w, l and h respectively |
| 89 | \return the value pointed by the given "key" |
| 90 | */ |
| 91 | void |
| 92 | GetWLH( |
| 93 | const OPENCITY_GRAPHIC_CODE gcode, |
| 94 | uint& w, const uint defw, |
| 95 | uint& l, const uint defl, |
| 96 | uint& h, const uint defh); |
| 97 | |
| 98 | private: |
| 99 | std::vector<Conf*> _vpConf; ///< The vector containing the model's configuration files |
| 100 | |
| 101 | |
| 102 | //======================================================================== |
| 103 | /** Return the string which represents the value part of the (key-value) |
| 104 | pair of the structure code given in parameter. |
| 105 | \param gcode The OpenCity graphic code of the structure that you want to |
| 106 | retrieve the parameter |
| 107 | \param key The key of the element that you what to retrieve the value |
| 108 | \param defaultValue The default value |
| 109 | \return the value pointed by the given "key" |
| 110 | */ |
| 111 | const string |
| 112 | propertymanagerGetStr( |
| 113 | const OPENCITY_GRAPHIC_CODE gcode, |
| 114 | const string& key, |
| 115 | const string& defaultValue = ""); |
| 116 | |
| 117 | |
| 118 | const OPENCITY_ERR_CODE |
| 119 | propertymanagerGetLint( |
| 120 | const OPENCITY_GRAPHIC_CODE gcode, |
| 121 | const string& key, |
| 122 | OC_LINT& rlint, |
| 123 | const OC_LINT defaultValue = 0); |
| 124 | }; |
| 125 | |
| 126 | #endif |