File: typetostr.cpp

package info (click to toggle)
libmuscle 3.7%2B4565-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,912 kB
  • sloc: cpp: 27,959; makefile: 58; sh: 26
file content (61 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download | duplicates (5)
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
#include "libMUSCLE/muscle.h"
#include <stdio.h>

namespace muscle {

const char *SecsToStr(unsigned long Secs)
	{
	static TLS<char[16]> Str;
	long hh, mm, ss;

	hh = Secs/(60*60);
	mm = (Secs/60)%60;
	ss = Secs%60;

	sprintf(Str.get(), "%02d:%02d:%02d", hh, mm, ss);
	return Str.get();
	}

const char *BoolToStr(bool b)
	{
	return b ? "True" : "False";
	}

const char *ScoreToStr(SCORE Score)
	{
	if (MINUS_INFINITY >= Score)
		return "       *";
// Hack to use "circular" buffer so when called multiple
// times in a printf-like argument list it works OK.
	const int iBufferCount = 16;
	const int iBufferLength = 16;
	static TLS<char[iBufferCount*iBufferLength]> szStr;
	static TLS<int> iBufferIndex(0);
	iBufferIndex.get() = (iBufferIndex.get() + 1)%iBufferCount;
	char *pStr = szStr.get() + iBufferIndex.get()*iBufferLength;
	sprintf(pStr, "%8g", Score);
	return pStr;
	}

// Left-justified version of ScoreToStr
const char *ScoreToStrL(SCORE Score)
	{
	if (MINUS_INFINITY >= Score)
		return "*";
// Hack to use "circular" buffer so when called multiple
// times in a printf-like argument list it works OK.
	const int iBufferCount = 16;
	const int iBufferLength = 16;
	static TLS<char[iBufferCount*iBufferLength]> szStr;
	static TLS<int> iBufferIndex(0);
	iBufferIndex.get() = (iBufferIndex.get() + 1)%iBufferCount;
	char *pStr = szStr.get() + iBufferIndex.get()*iBufferLength;
	sprintf(pStr, "%.3g", Score);
	return pStr;
	}

const char *WeightToStr(WEIGHT w)
	{
	return ScoreToStr(w);
	}
}