File: value-types.cc

package info (click to toggle)
gelemental 1.2.0-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,412 kB
  • ctags: 705
  • sloc: sh: 11,797; cpp: 5,255; makefile: 197
file content (584 lines) | stat: -rw-r--r-- 11,444 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/*
 * This file is part of libelemental, a periodic table library with detailed
 * information on elements.
 *
 * Copyright (C) 2006-2007 Kevin Daughtridge <kevin@kdau.com>
 * Copyright (C) 2003 Jonas Frantz <jonas.frantz@welho.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "private.hh"
#include <libelemental/value-types.hh>

#include <glibmm/date.h>

namespace Elemental {

	
//******************************************************************************
// class Message


Message::Message (const char* source, Qualifier qualifier_) throw ()
:	value_base (qualifier_), value (source)
{}


Message::Message (Qualifier qualifier_) throw ()
:	value_base (qualifier_)
{}


Message::~Message ()
{}


int
Message::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;
	
	if cast (&other, const Message, like_other)
		return do_get_string (ustring ()).collate_key ().compare
			(like_other->do_get_string (ustring ()).collate_key ());

	return 0;
}


ustring
Message::get_string (const ustring& format) const throw ()
{
	switch (qualifier)
	{
	case Q_EST:
	case Q_CA:
		// Translators: "(?) %1" prefixes a string indicating an inexact value.
		return compose::ucompose (_("(?) %1"), do_get_string (format));
	default:
		return value_base::get_string (format);
	}
}


ustring
Message::do_get_string (const ustring& format) const throw ()
{
	ustring result = _(value.data ());
	return format.empty () ? result : compose::ucompose (format, result);
}


//******************************************************************************
// class Event


Event::Event (int when_, const ustring& where_, Qualifier qualifier_) throw ()
:	value_base (qualifier_), when (when_), where (where_)
{
	always = true;
}


Event::Event (Qualifier qualifier_) throw ()
:	value_base (qualifier_)
{
	always = true;
}

Event::~Event ()
{}


int
Event::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;

	if cast (&other, const Event, like_other)
	{
		if (when < like_other->when)
			return -1;
		else if (when > like_other->when)
			return 1;
		else
			return 0;
	}

	return 0;
}


ustring
Event::get_string (const ustring& format) const throw ()
{
	switch (qualifier)
	{
	case Q_UNK: return _("Undiscovered");
	case Q_NA: return _("Known to the ancients");
	case Q_NEUTRAL:
	default:
		return do_get_string (format.empty () ? _("%1 (%2)") : format);
	}
}


ustring
Event::do_get_string (const ustring& format) const throw ()
{
	return compose::ucompose (format,
		Glib::Date (1, Glib::Date::JANUARY, when).format_string ("%Y"),
		_(where.data ()));
}


int
Event::compare_base (const value_base& other) const throw ()
{
	switch (qualifier)
	{
	case Q_UNK:
		return (other.qualifier == Q_UNK) ? 0 : 1;
	case Q_NA:
		return (other.qualifier == Q_NA) ? 0 : -1;
	case Q_NEUTRAL:
	default:
		switch (other.qualifier)
		{
		case Q_UNK:
			return -1;
		case Q_NA:
			return 1;
		case Q_NEUTRAL:
		default:
			return YIELD_COMPARE;
		}
	}
}


//******************************************************************************
// class Series


Series::Series (const Value& source, Qualifier qualifier_) throw ()
:	color_value_base (qualifier_), value (source)
{}


Series::Series (Qualifier qualifier_) throw ()
:	color_value_base (qualifier_)
{}


Series::~Series ()
{}


int
Series::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;

	if cast (&other, const Series, like_other)
	{
		if (int (value) < int (like_other->value))
			return -1;
		else if (int (value) > int (like_other->value))
			return 1;
		else
			return 0;
	}

	return 0;
}


color
Series::get_color () const throw ()
{
	if (has_value ())
		switch (value)
		{
		case NONMETAL:
			return Tango::CHAMELEON;
		case NOBLE_GAS:
			return Tango::SKY_BLUE;
		case ALKALI_METAL:
			return Tango::DARK_SCARLET_RED;
		case ALKALINE_EARTH_METAL:
			return Tango::ORANGE;
		case SEMIMETAL:
			return Tango::LIGHT_CHOCOLATE;
		case HALOGEN:
			return Tango::BUTTER;
		case POST_TRANSITION_METAL:
			return Tango::MEDIUM_ALUMINIUM;
		case TRANSITION_METAL:
			return Tango::LIGHT_SCARLET_RED;
		case LANTHANIDE:
			return Tango::LIGHT_PLUM;
		case ACTINIDE:
			return Tango::DARK_PLUM;
		}

	return Tango::LIGHT_ALUMINIUM;
}


ustring
Series::do_get_string (const ustring& format) const throw ()
{
	ustring result = _("(unknown)");

	switch (value)
	{
	case NONMETAL:
		result = _("Nonmetals"); break;
	case NOBLE_GAS:
		result = _("Noble gases"); break;
	case ALKALI_METAL:
		result = _("Alkali metals"); break;
	case ALKALINE_EARTH_METAL:
		result = _("Alkaline earth metals"); break;
	case SEMIMETAL:
		result = _("Semimetals"); break;
	case HALOGEN:
		result = _("Halogens"); break;
	case POST_TRANSITION_METAL:
		result = _("Post-transition metals"); break;
	case TRANSITION_METAL:
		result = _("Transition metals"); break;
	case LANTHANIDE:
		result = _("Lanthanides"); break;
	case ACTINIDE:
		result = _("Actinides"); break;
	}

	return format.empty () ? result : compose::ucompose (format, result);
}


//******************************************************************************
// class Block


Block::Block (const Value& source, Qualifier qualifier_) throw ()
:	color_value_base (qualifier_), value (source)
{}


Block::Block (Qualifier qualifier_) throw ()
:	color_value_base (qualifier_)
{}


Block::~Block ()
{}


int
Block::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;

	if cast (&other, const Block, like_other)
	{
		if (int (value) < int (like_other->value))
			return -1;
		else if (int (value) > int (like_other->value))
			return 1;
		else
			return 0;
	}

	return 0;
}


color
Block::get_color () const throw ()
{
	if (has_value ())
		switch (value)
		{
		case S:	return Tango::ORANGE;
		case P:	return Tango::BUTTER;
		case D:	return Tango::LIGHT_SCARLET_RED;
		case F:	return Tango::DARK_PLUM;
		}

	return Tango::LIGHT_ALUMINIUM;
}


ustring
Block::do_get_string (const ustring& format) const throw ()
{
	ustring result = _("(unknown)");

	switch (value)
	{
	case S: result = _("s-block"); break;
	case P: result = _("p-block"); break;
	case D: result = _("d-block"); break;
	case F: result = _("f-block"); break;
	}

	return format.empty () ? result : compose::ucompose (format, result);
}


//******************************************************************************
// class Phase


Phase::Phase (const Value& source, Qualifier qualifier_) throw ()
:	color_value_base (qualifier_), value (source)
{}


Phase::Phase (Qualifier qualifier_) throw ()
:	color_value_base (qualifier_)
{}


Phase::~Phase ()
{}


int
Phase::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;

	if cast (&other, const Phase, like_other)
	{
		if (int (value) < int (like_other->value))
			return -1;
		else if (int (value) > int (like_other->value))
			return 1;
		else
			return 0;
	}

	return 0;
}


color
Phase::get_color () const throw ()
{
	if (has_value ())
		switch (value)
		{
		case SOLID:
			return Tango::LIGHT_CHOCOLATE;
		case LIQUID:
			return Tango::CHAMELEON;
		case GAS:
			return Tango::SKY_BLUE;
		}

	return Tango::LIGHT_ALUMINIUM;
}


ustring
Phase::do_get_string (const ustring& format) const throw ()
{
	ustring result = _("(unknown)");

	switch (value)
	{
	case SOLID:
		result = _("Solid"); break;
	case LIQUID:
		result = _("Liquid"); break;
	case GAS:
		result = _("Gas"); break;
	}

	return format.empty () ? result : compose::ucompose (format, result);
}


//******************************************************************************
// class LatticeType


LatticeType::LatticeType (const Value& source, Qualifier qualifier_) throw ()
:	color_value_base (qualifier_), value (source)
{}


LatticeType::LatticeType (Qualifier qualifier_) throw ()
:	color_value_base (qualifier_)
{}


LatticeType::~LatticeType ()
{}


int
LatticeType::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;

	if cast (&other, const LatticeType, like_other)
	{
		if (int (value) < int (like_other->value))
			return -1;
		else if (int (value) > int (like_other->value))
			return 1;
		else
			return 0;
	}

	return 0;
}


color
LatticeType::get_color () const throw ()
{
	if (has_value ())
		switch (value)
		{
		case TRI:
			return Tango::CHAMELEON;
		case MONO:
			return Tango::SKY_BLUE;
		case ORTH:
			return Tango::ORANGE;
		case TET:
			return Tango::BUTTER;
		case RHO:
			return Tango::MEDIUM_ALUMINIUM;
		case HEX:
			return Tango::LIGHT_SCARLET_RED;
		case SC:
		case BCC:
		case FCC:
			return Tango::DARK_PLUM;
		}

	return Tango::LIGHT_ALUMINIUM;
}


ustring
LatticeType::do_get_string (const ustring& format) const throw ()
{
	ustring result = _("(unknown)");

	switch (value)
	{
	case TRI:
		result = _("Triclinic"); break;
	case MONO:
		result = _("Monoclinic"); break;
	case ORTH:
		result = _("Orthorhombic"); break;
	case TET:
		result = _("Tetragonal"); break;		
	case RHO:
		result = _("Rhombohedral"); break;
	case HEX:
		result = _("Hexagonal"); break;
	case SC:
		result = _("Simple cubic"); break;
	case BCC:
		result = _("Body-centered cubic"); break;
	case FCC:
		result = _("Face-centered cubic"); break;
	}

	return format.empty () ? result : compose::ucompose (format, result);
}


//******************************************************************************
// class ColorValue


ColorValue::ColorValue (const color& source, Qualifier qualifier_) throw ()
:	color_value_base (qualifier_), value (source)
{}


ColorValue::ColorValue (Qualifier qualifier_) throw ()
:	color_value_base (qualifier_)
{}


ColorValue::ColorValue (double position, Qualifier qualifier_) throw ()
:	color_value_base (qualifier_),
	value (Tango::BUTTER.composite (Tango::DARK_SCARLET_RED, position))
{}


ColorValue::~ColorValue ()
{}


int
ColorValue::compare (const value_base& other) const throw ()
{
	int base = compare_base (other);
	if (base != YIELD_COMPARE) return base;

	if cast (&other, const ColorValue, like_other)
	{
		double luminance = value.get_luminance (),
			other_luminance = like_other->value.get_luminance ();
		if (luminance < other_luminance)
			return -1;
		else if (luminance > other_luminance)
			return 1;
		else
			return 0;
	}

	return 0;
}


color
ColorValue::get_color () const throw ()
{
	if (has_value ())
		return value;
	else
		return Tango::LIGHT_ALUMINIUM;
}


ustring
ColorValue::do_get_string (const ustring& format) const throw ()
{
	ustring result = value.get_hex_spec ();
	return format.empty () ? result : compose::ucompose (format, result);
}


} // namespace Elemental