libRocket
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Property.h
Go to the documentation of this file.
1 /*
2  * This source file is part of libRocket, the HTML/CSS Interface Middleware
3  *
4  * For the latest information, see http://www.librocket.com
5  *
6  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  */
27 
28 #ifndef ROCKETCOREPROPERTY_H
29 #define ROCKETCOREPROPERTY_H
30 
31 #include "Variant.h"
32 #include "Header.h"
33 
34 namespace Rocket {
35 namespace Core {
36 
37 class PropertyDefinition;
38 
44 {
45 public:
46  enum Unit
47  {
48  UNKNOWN = 1 << 0,
49 
50  KEYWORD = 1 << 1, // generic keyword; fetch as < int >
51 
52  STRING = 1 << 2, // generic string; fetch as < String >
53 
54  // Absolute values.
55  NUMBER = 1 << 3, // number unsuffixed; fetch as < float >
56  PX = 1 << 4, // number suffixed by 'px'; fetch as < float >
57  COLOUR = 1 << 5, // colour; fetch as < Colourb >
58  ABSOLUTE_UNIT = NUMBER | PX | COLOUR,
59 
60  // Relative values.
61  EM = 1 << 6, // number suffixed by 'em'; fetch as < float >
62  PERCENT = 1 << 7, // number suffixed by '%'; fetch as < float >
63 
64  // Values based on pixels-per-inch.
65  INCH = 1 << 8, // number suffixed by 'in'; fetch as < float >
66  CM = 1 << 9, // number suffixed by 'cm'; fetch as < float >
67  MM = 1 << 10, // number suffixed by 'mm'; fetch as < float >
68  PT = 1 << 11, // number suffixed by 'pt'; fetch as < float >
69  PC = 1 << 12, // number suffixed by 'pc'; fetch as < float >
70  PPI_UNIT = INCH | CM | MM | PT | PC,
71 
72  REM = 1 << 13, // number suffixed by 'rem'; fetch as < float >
73  RELATIVE_UNIT = EM | REM | PERCENT
74  };
75 
76  Property();
77  template < typename PropertyType >
78  Property(PropertyType value, Unit unit, int specificity = -1) : value(Variant(value)), unit(unit), specificity(specificity)
79  {
80  definition = NULL;
81  parser_index = -1;
82 
83  source_line_number = 0;
84  }
85 
86  ~Property();
87 
89  String ToString() const;
90 
92  template <typename T>
93  T Get() const
94  {
95  return value.Get<T>();
96  }
97 
101 
104 
107 };
108 
109 }
110 }
111 
112 #endif
#define NULL
Definition: Types.h:33
Unit unit
Definition: Property.h:99
#define ROCKETCORE_API
Definition: Header.h:73
T Get() const
Templatised accessor.
Definition: Property.h:93
int parser_index
Definition: Property.h:103
Definition: PropertyDefinition.h:42
String source
Definition: Property.h:105
const PropertyDefinition * definition
Definition: Property.h:102
Definition: Clipboard.h:33
Definition: Variant.h:48
int specificity
Definition: Property.h:100
Property(PropertyType value, Unit unit, int specificity=-1)
Definition: Property.h:78
Definition: StringBase.h:42
int source_line_number
Definition: Property.h:106
Definition: Property.h:43
Unit
Definition: Property.h:46
Variant value
Definition: Property.h:98