diff options
| author | jhurst <jhurst@cinecert.com> | 2006-04-21 17:32:06 +0000 |
|---|---|---|
| committer | jhurst <> | 2006-04-21 17:32:06 +0000 |
| commit | 4e83acbf365d9b87dfdc95aef5c46785b33d2269 (patch) | |
| tree | ffb7c03653dae138339b79a5f52f4986061f4eb3 /src/KM_util.cpp | |
| parent | 34464c5616c053942cf7bdbb919bd8845cb0ceae (diff) | |
kumu merge
Diffstat (limited to 'src/KM_util.cpp')
| -rwxr-xr-x | src/KM_util.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/KM_util.cpp b/src/KM_util.cpp index c8cbb1c..bf61f94 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -36,10 +36,75 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <KM_log.h> #include <ctype.h> #include <list> +#include <map> #include <string> //------------------------------------------------------------------------------------------ +// Result_t Internals + +struct map_entry_t +{ + long rcode; + Kumu::Result_t* result; +}; + +const ui32_t MapMax = 512; +const ui32_t MapSize = MapMax * (sizeof(struct map_entry_t)); +static bool s_MapInit = false; +static struct map_entry_t s_ResultMap[MapSize]; + +// +const Kumu::Result_t& +Kumu::Result_t::Find(long v) +{ + for ( ui32_t i = 0; s_ResultMap[i].result != 0 && i < MapMax; i++ ) + { + if ( s_ResultMap[i].rcode == v ) + return *s_ResultMap[i].result; + } + + DefaultLogSink().Error("Unknown result code: %ld\n", v); + return RESULT_FAIL; +} + +// +Kumu::Result_t::Result_t(long v, const char* l) : value(v), label(l) +{ + assert(l); + + if ( ! s_MapInit ) + { + s_MapInit = true; + s_ResultMap[0].rcode = v; + s_ResultMap[0].result = this; + s_ResultMap[1].rcode = 0; + s_ResultMap[1].result = 0; + return; + } + + ui32_t i = 0; + while ( s_ResultMap[i].result != 0 && i < MapMax ) + { + i++; + if ( s_ResultMap[i].rcode == v ) + return; + } + + assert(i+2 < MapMax); + + s_ResultMap[i].rcode = v; + s_ResultMap[i].result = this; + s_ResultMap[i+1].rcode = 0; + s_ResultMap[i+1].result = 0; + return; +} + +Kumu::Result_t::~Result_t() {} + + +//------------------------------------------------------------------------------------------ + const char fill = '='; const char* base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -722,6 +787,49 @@ Kumu::Timestamp::EncodeString(char* str_buf, ui32_t buf_len) const // bool +Kumu::Timestamp::DecodeString(const char* datestr) +{ + if ( ! ( isdigit(datestr[0]) && isdigit(datestr[1]) && isdigit(datestr[2]) && isdigit(datestr[3]) ) + || datestr[4] != '-' + || ! ( isdigit(datestr[5]) && isdigit(datestr[6]) ) + || datestr[7] != '-' + || ! ( isdigit(datestr[8]) && isdigit(datestr[9]) ) + || datestr[10] != 'T' + || ! ( isdigit(datestr[11]) && isdigit(datestr[12]) ) + || datestr[13] != ':' + || ! ( isdigit(datestr[14]) && isdigit(datestr[15]) ) + || datestr[16] != ':' + || ! ( isdigit(datestr[17]) && isdigit(datestr[18]) ) + || ! ( datestr[19] == '-' || datestr[19] == '+' ) + || ! ( isdigit(datestr[20]) && isdigit(datestr[21]) ) + || datestr[22] != ':' + || ! ( isdigit(datestr[23]) && isdigit(datestr[24]) ) ) + return false; + + // TODO -- test this! + Year = atoi(datestr); + Month = atoi(datestr + 5); + Day = atoi(datestr + 8); + Hour = atoi(datestr + 11); + Minute = atoi(datestr + 14); + Second = atoi(datestr + 17); + + ui32_t TZ_hh = atoi(datestr + 20); + ui32_t TZ_mm = atoi(datestr + 23); + + if ( TZ_mm != 0 ) + DefaultLogSink().Error("Ignoring sub-hours timezone offset: %lu\n", TZ_mm); + + if ( TZ_hh > 12 ) + DefaultLogSink().Error("Ignoring large timezone offset: %s\n", (datestr+19)); + else + AddHours(TZ_hh); + + return true; +} + +// +bool Kumu::Timestamp::HasValue() const { if ( Year || Month || Day || Hour || Minute || Second ) |
