aboutsummaryrefslogtreecommitdiff
path: root/src/fstring.cpp
blob: f77e718a9eb68c895d7073c2582463ab26777e16 (plain)
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
/*
 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#define BU_TRACE
#include "bu/trace.h"

#include "bu/fstring.h"
#include "bu/hash.h"

template class Bu::FBasicString<char>;

template<> uint32_t Bu::__calcHashCode<Bu::FString>( const Bu::FString &k )
{
	long j, sz = k.getSize();
	const char *s = k.getStr();

	long nPos = 0;
	for( j = 0; j < sz; j++, s++ )
	{
		nPos = *s + (nPos << 6) + (nPos << 16) - nPos;
	}

	return nPos;
}

template<> bool Bu::__cmpHashKeys<Bu::FString>(
		const Bu::FString &a, const Bu::FString &b )
{
	return a == b;
}

std::basic_ostream<char>& operator<< (std::basic_ostream<char> &os, const Bu::FString &val )
{
	os.write( val.getStr(), val.getSize() );
	return os;
}

template<> void Bu::__tracer_format<Bu::FString>( const Bu::FString &v )
{
	printf("(%ld)\"%s\"", v.getSize(), v.getStr() );
}

bool &Bu::operator<<( bool &dst, const Bu::FString &sIn )
{
	if( sIn == "true" || sIn == "yes" || sIn == "t" )
		dst = true;
	else
		dst = false;

	return dst;
}

uint8_t &Bu::operator<<( uint8_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%hhu", &dst );
	return dst;
}

int8_t &Bu::operator<<( int8_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%hhd", &dst );
	return dst;
}

char &Bu::operator<<( char &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%hhd", &dst );
	return dst;
}

uint16_t &Bu::operator<<( uint16_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%hu", &dst );
	return dst;
}

int16_t &Bu::operator<<( int16_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%hd", &dst );
	return dst;
}

uint32_t &Bu::operator<<( uint32_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%u", &dst );
	return dst;
}

int32_t &Bu::operator<<( int32_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%d", &dst );
	return dst;
}

uint64_t &Bu::operator<<( uint64_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%llu", &dst );
	return dst;
}

int64_t &Bu::operator<<( int64_t &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%lld", &dst );
	return dst;
}

float &Bu::operator<<( float &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%f", &dst );
	return dst;
}

double &Bu::operator<<( double &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%lf", &dst );
	return dst;
}

long double &Bu::operator<<( long double &dst, const Bu::FString &sIn )
{
	sscanf( sIn.getStr(), "%Lf", &dst );
	return dst;
}

Bu::FString &Bu::operator<<( Bu::FString &dst, const Bu::FString &sIn )
{
	dst = sIn;
	return dst;
}