rosserial for Hydro
Fork of rosserial_mbed_lib by
time.cpp@3:1cf99502f396, 2011-11-12 (annotated)
- Committer:
- nucho
- Date:
- Sat Nov 12 23:54:45 2011 +0000
- Revision:
- 3:1cf99502f396
- Parent:
- 0:77afd7560544
- Child:
- 5:c30c76e8c3f1
This program supported the revision of 167 of rosserial.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:77afd7560544 | 1 | /* |
nucho | 0:77afd7560544 | 2 | * Software License Agreement (BSD License) |
nucho | 0:77afd7560544 | 3 | * |
nucho | 0:77afd7560544 | 4 | * Copyright (c) 2011, Willow Garage, Inc. |
nucho | 0:77afd7560544 | 5 | * All rights reserved. |
nucho | 0:77afd7560544 | 6 | * |
nucho | 0:77afd7560544 | 7 | * Redistribution and use in source and binary forms, with or without |
nucho | 0:77afd7560544 | 8 | * modification, are permitted provided that the following conditions |
nucho | 0:77afd7560544 | 9 | * are met: |
nucho | 0:77afd7560544 | 10 | * |
nucho | 0:77afd7560544 | 11 | * * Redistributions of source code must retain the above copyright |
nucho | 0:77afd7560544 | 12 | * notice, this list of conditions and the following disclaimer. |
nucho | 0:77afd7560544 | 13 | * * Redistributions in binary form must reproduce the above |
nucho | 0:77afd7560544 | 14 | * copyright notice, this list of conditions and the following |
nucho | 0:77afd7560544 | 15 | * disclaimer in the documentation and/or other materials provided |
nucho | 0:77afd7560544 | 16 | * with the distribution. |
nucho | 0:77afd7560544 | 17 | * * Neither the name of Willow Garage, Inc. nor the names of its |
nucho | 0:77afd7560544 | 18 | * contributors may be used to endorse or promote prducts derived |
nucho | 0:77afd7560544 | 19 | * from this software without specific prior written permission. |
nucho | 0:77afd7560544 | 20 | * |
nucho | 0:77afd7560544 | 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
nucho | 0:77afd7560544 | 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
nucho | 0:77afd7560544 | 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
nucho | 0:77afd7560544 | 24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
nucho | 0:77afd7560544 | 25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
nucho | 0:77afd7560544 | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
nucho | 0:77afd7560544 | 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
nucho | 0:77afd7560544 | 28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nucho | 0:77afd7560544 | 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
nucho | 0:77afd7560544 | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
nucho | 0:77afd7560544 | 31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
nucho | 0:77afd7560544 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
nucho | 0:77afd7560544 | 33 | */ |
nucho | 0:77afd7560544 | 34 | |
nucho | 0:77afd7560544 | 35 | /* |
nucho | 0:77afd7560544 | 36 | * Author: Michael Ferguson |
nucho | 0:77afd7560544 | 37 | */ |
nucho | 0:77afd7560544 | 38 | |
nucho | 0:77afd7560544 | 39 | #include "ros/time.h" |
nucho | 0:77afd7560544 | 40 | #include "ros.h" |
nucho | 0:77afd7560544 | 41 | |
nucho | 0:77afd7560544 | 42 | |
nucho | 0:77afd7560544 | 43 | namespace ros |
nucho | 0:77afd7560544 | 44 | { |
nucho | 0:77afd7560544 | 45 | void normalizeSecNSec(unsigned long& sec, unsigned long& nsec){ |
nucho | 0:77afd7560544 | 46 | unsigned long nsec_part= nsec % 1000000000UL; |
nucho | 0:77afd7560544 | 47 | unsigned long sec_part = nsec / 1000000000UL; |
nucho | 0:77afd7560544 | 48 | sec += sec_part; |
nucho | 0:77afd7560544 | 49 | nsec = nsec_part; |
nucho | 0:77afd7560544 | 50 | } |
nucho | 0:77afd7560544 | 51 | |
nucho | 0:77afd7560544 | 52 | Time& Time::fromNSec(long t) |
nucho | 0:77afd7560544 | 53 | { |
nucho | 0:77afd7560544 | 54 | sec = t / 1000000000; |
nucho | 0:77afd7560544 | 55 | nsec = t % 1000000000; |
nucho | 0:77afd7560544 | 56 | normalizeSecNSec(sec, nsec); |
nucho | 0:77afd7560544 | 57 | return *this; |
nucho | 0:77afd7560544 | 58 | } |
nucho | 0:77afd7560544 | 59 | |
nucho | 0:77afd7560544 | 60 | Time& Time::operator +=(const Duration &rhs) |
nucho | 0:77afd7560544 | 61 | { |
nucho | 0:77afd7560544 | 62 | sec += rhs.sec; |
nucho | 0:77afd7560544 | 63 | nsec += rhs.nsec; |
nucho | 0:77afd7560544 | 64 | normalizeSecNSec(sec, nsec); |
nucho | 0:77afd7560544 | 65 | return *this; |
nucho | 0:77afd7560544 | 66 | } |
nucho | 0:77afd7560544 | 67 | |
nucho | 0:77afd7560544 | 68 | Time& Time::operator -=(const Duration &rhs){ |
nucho | 0:77afd7560544 | 69 | sec += -rhs.sec; |
nucho | 0:77afd7560544 | 70 | nsec += -rhs.nsec; |
nucho | 0:77afd7560544 | 71 | normalizeSecNSec(sec, nsec); |
nucho | 0:77afd7560544 | 72 | return *this; |
nucho | 0:77afd7560544 | 73 | } |
nucho | 0:77afd7560544 | 74 | |
nucho | 0:77afd7560544 | 75 | |
nucho | 0:77afd7560544 | 76 | } |