MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / cast

Method cast

src/Variant.cpp:1902–2073  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

1900
1901////////////////////////////////////////////////////////////////////////////////
1902void Variant::cast(const enum type new_type) {
1903 // Short circuit.
1904 if (_type == new_type) return;
1905
1906 // From type_boolean
1907 switch (_type) {
1908 case type_boolean:
1909 switch (new_type) {
1910 case type_boolean:
1911 break;
1912 case type_integer:
1913 _integer = _bool ? 1 : 0;
1914 break;
1915 case type_real:
1916 _real = _bool ? 1.0 : 0.0;
1917 break;
1918 case type_string:
1919 _string = _bool ? "true" : "false";
1920 break;
1921 case type_date:
1922 _date = _bool ? 1 : 0;
1923 break;
1924 case type_duration:
1925 _duration = _bool ? 1 : 0;
1926 break;
1927 }
1928 break;
1929
1930 case type_integer:
1931 switch (new_type) {
1932 case type_boolean:
1933 _bool = _integer == 0 ? false : true;
1934 break;
1935 case type_integer:
1936 break;
1937 case type_real:
1938 _real = static_cast<double>(_integer);
1939 break;
1940 case type_string: {
1941 char temp[24];
1942 snprintf(temp, 24, "%lld", _integer);
1943 _string = temp;
1944 } break;
1945 case type_date:
1946 _date = (time_t)_integer;
1947 break;
1948 case type_duration:
1949 _duration = (time_t)_integer;
1950 break;
1951 }
1952 break;
1953
1954 case type_real:
1955 switch (new_type) {
1956 case type_boolean:
1957 _bool = _real == 0.0 ? false : true;
1958 break;
1959 case type_integer:

Callers 15

TEST_NAMEFunction · 0.80
evaluatePostfixStackMethod · 0.80
operator&&Method · 0.80
operator||Method · 0.80
operator_xorMethod · 0.80
operator<Method · 0.80
operator<=Method · 0.80
operator>Method · 0.80
operator>=Method · 0.80
operator==Method · 0.80
operator_matchMethod · 0.80
operator_partialMethod · 0.80

Calls 1

parseMethod · 0.80

Tested by 1

TEST_NAMEFunction · 0.64