Mercurial > forge
comparison main/database/src/converters.cc @ 11710:4f5471a9bce6 octave-forge
Added converters for bit string types.
author | i7tiol |
---|---|
date | Sat, 18 May 2013 13:22:09 +0000 |
parents | 4f95e5c4a57a |
children | f4c52c68f744 |
comparison
equal
deleted
inserted
replaced
11709:4f95e5c4a57a | 11710:4f5471a9bce6 |
---|---|
1886 &to_octave_bin_macaddr, | 1886 &to_octave_bin_macaddr, |
1887 &from_octave_str_macaddr, | 1887 &from_octave_str_macaddr, |
1888 &from_octave_bin_macaddr}; | 1888 &from_octave_bin_macaddr}; |
1889 | 1889 |
1890 /* end type macaddr */ | 1890 /* end type macaddr */ |
1891 | |
1892 /* type bit */ | |
1893 | |
1894 int to_octave_str_bit (const octave_pq_connection &conn, | |
1895 const char *c, octave_value &ov, int nb) | |
1896 { | |
1897 return 1; | |
1898 } | |
1899 | |
1900 int to_octave_bin_bit (const octave_pq_connection &conn, | |
1901 const char *c, octave_value &ov, int nb) | |
1902 { | |
1903 int32_t nbits = int32_t (be32toh (*((int32_t *) c))); | |
1904 | |
1905 c += 4; | |
1906 | |
1907 int32_t nbytes = (nbits + 7) / 8; | |
1908 | |
1909 uint8NDArray a (dim_vector (nbytes, 1)); | |
1910 | |
1911 for (int i = 0; i < nbytes; i++, c++) | |
1912 a(i) = uint8_t (*c); | |
1913 | |
1914 octave_scalar_map tp; | |
1915 tp.assign ("bitlen", octave_value (octave_int32 (nbits))); | |
1916 tp.assign ("bits", octave_value (a)); | |
1917 | |
1918 ov = octave_value (tp); | |
1919 | |
1920 return 0; | |
1921 } | |
1922 | |
1923 int from_octave_str_bit (const octave_pq_connection &conn, | |
1924 const octave_value &ov, oct_pq_dynvec_t &val) | |
1925 { | |
1926 return 1; | |
1927 } | |
1928 | |
1929 int from_octave_bin_bit (const octave_pq_connection &conn, | |
1930 const octave_value &ov, oct_pq_dynvec_t &val) | |
1931 { | |
1932 octave_scalar_map tp = ov.scalar_map_value (); | |
1933 if (error_state || ! tp.isfield ("bitlen") || ! tp.isfield ("bits")) | |
1934 { | |
1935 error ("can not convert octave_value to bitstring representation"); | |
1936 return 1; | |
1937 } | |
1938 | |
1939 int32_t nbits = tp.contents ("bitlen").int_value (); | |
1940 | |
1941 uint8NDArray a = tp.contents ("bits").uint8_array_value (); | |
1942 | |
1943 if (error_state || nbits < 0) | |
1944 { | |
1945 error ("can not convert octave_value to bitstring representation"); | |
1946 return 1; | |
1947 } | |
1948 | |
1949 int32_t nbytes = (nbits + 7) / 8; | |
1950 | |
1951 if (a.numel () != nbytes) | |
1952 { | |
1953 error ("wrong number of elements in bitstring representation"); | |
1954 return 1; | |
1955 } | |
1956 | |
1957 OCT_PQ_PUT(val, int32_t, htobe32 (nbits)) | |
1958 | |
1959 for (int i = 0; i < nbytes; i++) | |
1960 val.push_back (a(i).value ()); | |
1961 | |
1962 return 0; | |
1963 } | |
1964 | |
1965 oct_pq_conv_t conv_bit = {0, | |
1966 0, | |
1967 oct_pq_el_oids_t (), | |
1968 oct_pq_conv_cache_t (), | |
1969 false, | |
1970 false, | |
1971 false, | |
1972 "bit", | |
1973 &to_octave_str_bit, | |
1974 &to_octave_bin_bit, | |
1975 &from_octave_str_bit, | |
1976 &from_octave_bin_bit}; | |
1977 | |
1978 /* end type bit */ | |
1979 | |
1980 /* type varbit */ | |
1981 | |
1982 oct_pq_conv_t conv_varbit = {0, | |
1983 0, | |
1984 oct_pq_el_oids_t (), | |
1985 oct_pq_conv_cache_t (), | |
1986 false, | |
1987 false, | |
1988 false, | |
1989 "varbit", | |
1990 &to_octave_str_bit, | |
1991 &to_octave_bin_bit, | |
1992 &from_octave_str_bit, | |
1993 &from_octave_bin_bit}; | |
1994 | |
1995 /* end type varbit */ | |
1891 | 1996 |
1892 oct_pq_conv_t *t_conv_ptrs[OCT_PQ_NUM_CONVERTERS] = {&conv_bool, | 1997 oct_pq_conv_t *t_conv_ptrs[OCT_PQ_NUM_CONVERTERS] = {&conv_bool, |
1893 &conv_oid, | 1998 &conv_oid, |
1894 &conv_float8, | 1999 &conv_float8, |
1895 &conv_float4, | 2000 &conv_float4, |
1916 &conv_polygon, | 2021 &conv_polygon, |
1917 &conv_path, | 2022 &conv_path, |
1918 &conv_unknown, | 2023 &conv_unknown, |
1919 &conv_cidr, | 2024 &conv_cidr, |
1920 &conv_inet, | 2025 &conv_inet, |
1921 &conv_macaddr}; | 2026 &conv_macaddr, |
2027 &conv_bit, | |
2028 &conv_varbit}; | |
1922 | 2029 |
1923 oct_pq_conv_ptrs_t conv_ptrs (OCT_PQ_NUM_CONVERTERS, t_conv_ptrs); | 2030 oct_pq_conv_ptrs_t conv_ptrs (OCT_PQ_NUM_CONVERTERS, t_conv_ptrs); |