Skip to content

Commit

Permalink
Merge pull request #1677 from drdanz/YARP_INT
Browse files Browse the repository at this point in the history
Properly handle 8,16,32,64 bit integers and 32,64 bit floating point values
  • Loading branch information
drdanz committed May 22, 2018
2 parents afa90b5 + 95a2812 commit 5313b8e
Show file tree
Hide file tree
Showing 489 changed files with 8,780 additions and 7,617 deletions.
4 changes: 2 additions & 2 deletions bindings/chicken/example/example.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
(let ((bottle (BufferedPortBottle-prepare p)))
(Bottle-clear bottle)
(Bottle-addString bottle "count")
(Bottle-addInt bottle i)
(Bottle-addInt32 bottle i)
(Bottle-addString bottle "of")
(Bottle-addInt bottle top)
(Bottle-addInt32 bottle top)
(display "Sending ")
(display (Bottle-toString bottle))
(newline)
Expand Down
4 changes: 2 additions & 2 deletions bindings/csharp/examples/example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ static void Main(string[] args)
Bottle bottle = p.prepare();
bottle.clear();
bottle.addString("count");
bottle.addInt(i);
bottle.addInt32(i);
bottle.addString("of");
bottle.addInt(top);
bottle.addInt32(top);
Console.WriteLine("Sending " + bottle.toString());
p.write();
Time.delay(0.5);
Expand Down
2 changes: 1 addition & 1 deletion bindings/java/examples/Example1.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void main(String[] args) {
Network.connect("/foo","/bar");
while(true) {
Bottle bot = new Bottle();
bot.addDouble(10.4);
bot.addFloat64(10.4);
bot.addString("bozo");
System.out.println("sending bottle: " + bot);
p.write(bot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
global dPort;
dBottle=yarp.Bottle;
for i=1:1:numDoubles;
dBottle.addDouble(u(i));
dBottle.addFloat64(u(i));
end;
dPort.write(dBottle);
sys = [];
Expand Down
4 changes: 2 additions & 2 deletions bindings/lua/examples/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ for i=1,100 do
local wb = port:prepare()
wb:clear()
wb:addString("count")
wb:addInt(i)
wb:addInt32(i)
wb:addString("of")
wb:addInt(100)
wb:addInt32(100)
print(string.format("Sending: %s", wb:toString()))
port:write()
yarp.Time_delay(0.5)
Expand Down
4 changes: 2 additions & 2 deletions bindings/lua/examples/example2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ for i=1,10 do
local wb = sender:prepare()
wb:clear()
wb:addString("count")
wb:addInt(i)
wb:addInt32(i)
wb:addString("of")
wb:addInt(10)
wb:addInt32(10)
sender:write()

-- read from receiver port
Expand Down
4 changes: 2 additions & 2 deletions bindings/octave/examples/example.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
wb = p.prepare();
wb.clear();
wb.addString('count');
wb.addInt(i);
wb.addInt32(i);
wb.addString('of');
wb.addInt(100);
wb.addInt32(100);
p.write();
wb.toString()
yarp.Time.delay(0.5)
Expand Down
4 changes: 2 additions & 2 deletions bindings/perl/examples/example.pl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
my $bottle = $p->prepare();
$bottle->clear();
$bottle->addString("count");
$bottle->addInt($i);
$bottle->addInt32($i);
$bottle->addString("of");
$bottle->addInt($top);
$bottle->addInt32($top);
print "Sending ", $bottle->toString(), "\n";
$p->write();
yarp::Time::delay(0.5);
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
bottle = p.prepare()
bottle.clear()
bottle.addString("count")
bottle.addInt(i)
bottle.addInt32(i)
bottle.addString("of")
bottle.addInt(top)
bottle.addInt32(top)
print ("Sending", bottle.toString())
p.write()
yarp.Time.delay(0.5)
Expand Down
4 changes: 2 additions & 2 deletions bindings/ruby/examples/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
bottle = p.prepare()
bottle.clear()
bottle.addString("count")
bottle.addInt(i)
bottle.addInt32(i)
bottle.addString("of")
bottle.addInt(top)
bottle.addInt32(top)
puts "Sending", bottle.toString()
p.write()
Yarp::Time.delay(0.5)
Expand Down
4 changes: 2 additions & 2 deletions bindings/tcl/examples/example.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ for {set i 1} {$i<=$top} {incr i} {
set bottle [p prepare]
$bottle clear
$bottle addString "count"
$bottle addInt $i
$bottle addInt32 $i
$bottle addString "of"
$bottle addInt $top
$bottle addInt32 $top
puts [concat "Sending " [$bottle toString]]
p write
Time_delay 0.5
Expand Down
152 changes: 78 additions & 74 deletions cmake/YarpSystemCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
#########################################################################
# Check whether system is big- or little- endian

unset(YARP_BIG_ENDIAN)
unset(YARP_LITTLE_ENDIAN)

test_big_endian(IS_BIG_ENDIAN)
if(${IS_BIG_ENDIAN})
set(YARP_BIG_ENDIAN 1)
Expand All @@ -53,90 +56,91 @@ endif()


#########################################################################
# Find 16, 32, and 64 bit types, portably

set(YARP_INT16)
set(YARP_INT32)
set(YARP_INT64)
set(YARP_FLOAT32)
set(YARP_FLOAT64)

check_type_size("short" SIZEOF_SHORT)
check_type_size("int" SIZEOF_INT)
check_type_size("long" SIZEOF_LONG)
if(SIZEOF_INT EQUAL 4)
set(YARP_INT32 "int")
set(YARP_INT32_FMT "d")
else()
if(SIZEOF_SHORT EQUAL 4)
set(YARP_INT32 "short")
set(YARP_INT32_FMT "hd")
elseif(SIZEOF_LONG EQUAL 4)
set(YARP_INT32 "long")
set(YARP_INT32_FMT "ld")
endif()
endif()
# Check size of pointers

check_type_size("void *" YARP_POINTER_SIZE)


#########################################################################
# Find 32, 64 and optionally 128-bit floating point types and check whether
# floating point types are IEC559

unset(YARP_FLOAT32)
unset(YARP_FLOAT64)
unset(YARP_FLOAT128)

set(YARP_FLOAT32_IS_IEC559 0)
set(YARP_FLOAT64_IS_IEC559 0)
set(YARP_FLOAT128_IS_IEC559 0)

set(YARP_HAS_FLOAT128_T 0)


macro(CHECK_FLOATING_POINT_IS_IEC559 _type)
string(REPLACE " " "_" _type_s "${_type}")
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_type_s}-is_iec559.cpp"
"#include <limits>
int main() {
return std::numeric_limits<${_type}>::is_iec559 ? 1 : 0;
}
")

try_run(YARP_${_type_s}_IS_IEC559
_unused
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_type_s}-is_iec559.cpp")
endmacro()

check_floating_point_is_iec559("float")
check_floating_point_is_iec559("double")
check_floating_point_is_iec559("long double")


if(SIZEOF_SHORT EQUAL 2)
set(YARP_INT16 "short")
else()
# Hmm - there's no other native type to get 16 bits
# We will continue since most people using YARP do not need one.
message(STATUS "Warning: cannot find a 16 bit type on your system")
message(STATUS "Continuing...")
endif()

check_type_size("float" SIZEOF_FLOAT)
check_type_size("double" SIZEOF_DOUBLE)
if(SIZEOF_DOUBLE EQUAL 8)
set(YARP_FLOAT64 "double")
elseif(SIZEOF_FLOAT EQUAL 8)
set(YARP_FLOAT64 "float")
endif()
check_type_size("long double" SIZEOF_LONG_DOUBLE)

if(SIZEOF_DOUBLE EQUAL 4)
set(YARP_FLOAT32 "double")
if(YARP_float_IS_IEC559)
set(YARP_FLOAT32 "float")
set(YARP_FLOAT32_IS_IEC559 1)
elseif(SIZEOF_FLOAT EQUAL 4)
set(YARP_FLOAT32 "float")
elseif(SIZEOF_DOUBLE EQUAL 4)
set(YARP_FLOAT32 "double")
elseif(SIZEOF_LONG_DOUBLE EQUAL 4)
set(YARP_FLOAT32 "long double")
endif()

if(SIZEOF_LONG EQUAL 8)
set(YARP_INT64 "long")
set(YARP_INT64_FMT "ld")
else()
check_type_size("long long" SIZEOF_LONGLONG)
if(SIZEOF_LONGLONG EQUAL 8)
set(YARP_INT64 "long long")
else()
check_type_size("__int64" SIZEOF___INT64)
if(SIZEOF___INT64 EQUAL 8)
set(YARP_INT64 "__int64")
endif()
endif()
set(YARP_INT64_FMT "lld")
if(NOT YARP_FLOAT32)
message(FATAL_ERROR "Cannot find a 32-bit floating point type")
endif()

check_type_size("void *" YARP_POINTER_SIZE)

if(YARP_double_IS_IEC559)
set(YARP_FLOAT64 "double")
set(YARP_FLOAT64_IS_IEC559 1)
elseif(SIZEOF_DOUBLE EQUAL 8)
set(YARP_FLOAT64 "double")
elseif(SIZEOF_LONG_DOUBLE EQUAL 8)
set(YARP_FLOAT64 "long double")
elseif(SIZEOF_FLOAT EQUAL 8)
set(YARP_FLOAT64 "float")
endif()
if(NOT YARP_FLOAT64)
message(FATAL_ERROR "Cannot find a 64-bit floating point type")
endif()

set(YARP_SSIZE_T int)
check_type_size(ssize_t YARP_SSIZE_T_LOWER)
if(HAVE_YARP_SSIZE_T_LOWER)
set(YARP_SSIZE_T ssize_t)
else()
check_type_size(SSIZE_T YARP_SSIZE_T_HIGHER)
if(HAVE_YARP_SSIZE_T_HIGHER)
set(YARP_SSIZE_T SSIZE_T)
else()
check_type_size(size_t YARP_SIZE_T)
if(YARP_SIZE_T EQUAL 8)
set(YARP_SSIZE_T ${YARP_INT64})
elseif(YARP_SIZE_T EQUAL 4)
set(YARP_SSIZE_T ${YARP_INT32})
elseif(YARP_SIZE_T EQUAL 2)
set(YARP_SSIZE_T ${YARP_INT16})
endif()
endif()
if(YARP_long_double_IS_IEC559)
set(YARP_FLOAT128 "long double")
set(YARP_FLOAT128_IS_IEC559 1)
elseif(SIZEOF_LONG_DOUBLE EQUAL 16)
set(YARP_FLOAT128 "long double")
elseif(SIZEOF_DOUBLE EQUAL 16)
set(YARP_FLOAT128 "double")
elseif(SIZEOF_FLOAT EQUAL 16)
set(YARP_FLOAT128 "float")
endif()
if(YARP_FLOAT128)
set(YARP_HAS_FLOAT128_T 1)
endif()


Expand Down Expand Up @@ -168,7 +172,7 @@ check_floating_point_exponent_digits(LDBL)
#########################################################################
# Set up compile flags

add_definitions(-DYARP_PRESENT)
add_definitions(-DBUILDING_YARP)
add_definitions(-D_REENTRANT)
set_property(GLOBAL APPEND PROPERTY YARP_DEFS -D_REENTRANT)

Expand Down
6 changes: 5 additions & 1 deletion cmake/template/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,11 @@ PREDEFINED = __cplusplus:=201103L \
YARP_run_API= \
YARP_rtf_API= \
Q_SLOTS=slots \
Q_SIGNALS=signals
Q_SIGNALS=signals \
YARP_DEPRECATED= \
YARP_DEPRECATED_MSG(MSG)= \
YARP_DEPRECATED_INTERNAL= \
YARP_DEPRECATED_INTERNAL_MSG(MSG)=

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
4 changes: 2 additions & 2 deletions doc/note_devices.dox
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public:
virtual bool open(yarp::os::Searchable& config) {
// extract width and height configuration, if present
// otherwise use 128x128
int desiredWidth = config.check("w",Value(128)).asInt();
int desiredHeight = config.check("h",Value(128)).asInt();
int desiredWidth = config.check("w",Value(128)).asInt32();
int desiredHeight = config.check("h",Value(128)).asInt32();
return open(desiredWidth,desiredHeight);
}

Expand Down
28 changes: 14 additions & 14 deletions doc/port_expert.dox
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public:
NetInt32 x;
NetInt32 y;
Target() {
tag = BOTTLE_TAG_LIST + BOTTLE_TAG_INT;
tag = BOTTLE_TAG_LIST + BOTTLE_TAG_INT32;
len = 2;
}
};
Expand All @@ -348,13 +348,13 @@ public:
int x;
int y;
virtual bool write(ConnectionWriter& connection) {
connection.appendInt(x);
connection.appendInt(y);
connection.appendInt32(x);
connection.appendInt32(y);
return true;
}
virtual bool read(ConnectionReader& connection) {
x = connection.expectInt();
y = connection.expectInt();
x = connection.expectInt32();
y = connection.expectInt32();
return !connection.isError();
}
};
Expand All @@ -377,10 +377,10 @@ rpc"), or a web-browser, etc. For example, we could make Target's
write method be:
\code
virtual bool write(ConnectionWriter& connection) {
connection.appendInt(BOTTLE_TAG_LIST+BOTTLE_TAG_INT);
connection.appendInt(2); // two elements
connection.appendInt(x);
connection.appendInt(y);
connection.appendInt32(BOTTLE_TAG_LIST+BOTTLE_TAG_INT32);
connection.appendInt32(2); // two elements
connection.appendInt32(x);
connection.appendInt32(y);
connection.convertTextMode(); // if connection is text-mode, convert!
return true;
}
Expand All @@ -398,12 +398,12 @@ The corresponding read method would be:
\code
virtual bool read(ConnectionReader& connection) {
connection.convertTextMode(); // if connection is text-mode, convert!
int tag = connection.expectInt();
if (tag!=BOTTLE_TAG_LIST+BOTTLE_TAG_INT) return false;
int ct = connection.expectInt();
int tag = connection.expectInt32();
if (tag!=BOTTLE_TAG_LIST+BOTTLE_TAG_INT32) return false;
int ct = connection.expectInt32();
if (ct!=2) return false;
x = connection.expectInt();
y = connection.expectInt();
x = connection.expectInt32();
y = connection.expectInt32();
return !connection.isError();
}
\endcode
Expand Down
Loading

0 comments on commit 5313b8e

Please sign in to comment.