public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [c++0x] <date_time> implementation, take 2
@ 2008-03-10  4:17 Pedro Lamarão
  2008-03-10 12:41 ` Paolo Carlini
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Lamarão @ 2008-03-10  4:17 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Here goes. The patch was generated with svn diff.

It defines get_system_time using std::time; we can add support for more 
precise stuff later.

Attached in a tarball is a testsuite for std::nanoseconds and 
std::system_time.

2008-03-10  Pedro Lamarão  <pedro.lamarao@gmail.com>

	* include/std/date_time: new file.
	* src/date_time.cpp: new file.
	* config/abi/pre/gnu.ver: get_system_time is a new symbol
	in version GLIBCXX_3.4.11.
	* include/Makefile.am: add date_time in std headers.
	* src/Makefile.am: add date_time.cc to source files.

--
  P.

[-- Attachment #2: 31_date_time.tar.bz2 --]
[-- Type: application/x-bzip, Size: 2052 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: date_time.patch --]
[-- Type: text/x-patch; name="date_time.patch", Size: 10073 bytes --]

Index: src/date_time.cc
===================================================================
--- src/date_time.cc	(revisão 0)
+++ src/date_time.cc	(revisão 0)
@@ -0,0 +1,41 @@
+// Copyright (C) 2008
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <date_time>
+
+namespace std
+{
+
+  system_time
+  get_system_time()
+  {
+    time_t sec = time(0);
+    return system_time(sec);
+  }
+
+}
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revisão 133071)
+++ src/Makefile.am	(cópia de trabalho)
@@ -141,6 +141,7 @@
 	compatibility.cc \
 	complex_io.cc \
 	ctype.cc \
+	date_time.cc \
 	debug.cc \
 	functexcept.cc \
 	hash.cc \
@@ -242,6 +243,11 @@
 hashtable_c++0x.o: hashtable_c++0x.cc
 	$(CXXCOMPILE) -std=gnu++0x -c $<
 
+date_time.lo: date_time.cc
+	$(LTCXXCOMPILE) -std=gnu++0x -c $<
+date_time.o: date_time.cc
+	$(CXXCOMPILE) -std=gnu++0x -c $<
+
 if GLIBCXX_LDBL_COMPAT
 # Use special rules for compatibility-ldbl.cc compilation, as we need to
 # pass -mlong-double-64.
Index: include/std/date_time
===================================================================
--- include/std/date_time	(revisão 0)
+++ include/std/date_time	(revisão 0)
@@ -0,0 +1,237 @@
+// <date_time> -*- C++ -*-
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING.  If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file include/date_time
+ *  This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_DATE_TIME
+#define _GLIBCXX_DATE_TIME 1
+
+#pragma GCC system_header
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+# include <c++0x_warning.h>
+#endif
+
+#include <ctime>
+
+namespace std
+{
+
+  // duration types
+  
+  class nanoseconds
+  {
+  public:
+  
+    // traits information
+    typedef long long tick_type;
+    static const tick_type ticks_per_second = 1000L * 1000 * 1000;
+    static const tick_type seconds_per_tick = 0;
+    static const bool is_subsecond = true;
+  
+    // construct/copy/destroy
+    nanoseconds(long long ns = 0) : ns(ns) { }
+  
+    // modifiers
+    template<typename RhsDuration>
+      nanoseconds&
+      operator+=(const RhsDuration& d);
+  
+    template<typename RhsDuration>
+      nanoseconds&
+      operator-=(const RhsDuration& d);
+  
+    nanoseconds&
+    operator*=(long multiplier);
+  
+    nanoseconds&
+    operator/=(long divisor);
+  
+    // observers
+    tick_type count() const { return ns; }
+  
+    // operations
+    nanoseconds operator-() const { return nanoseconds(-ns); }
+  
+  private:
+    tick_type ns;
+  };
+  
+  class microseconds;
+  class milliseconds;
+  class seconds;
+  class minutes;
+  class hours;
+  
+  // timepoint type
+  class system_time
+  {
+  public:
+  
+    // traits information
+    typedef nanoseconds::tick_type tick_type;
+    static const tick_type ticks_per_second = nanoseconds::ticks_per_second;
+    static const tick_type seconds_per_tick = 0;
+    static const bool is_subsecond = true;
+  
+    // create/copy/destroy
+  
+    system_time() : tv_sec(0), tv_nsec(0) { }
+  
+    explicit system_time(time_t s, nanoseconds ns = 0)
+    : tv_sec(s), tv_nsec(0) { }
+  
+    time_t
+    seconds_since_epoch() const { return tv_sec; }
+  
+    nanoseconds
+    nanoseconds_since_epoch() const
+    {
+      return nanoseconds(tv_nsec + tv_sec * ticks_per_second);
+    }
+  
+    // comparison functions
+  
+    bool operator==(const system_time& rhs) const
+    {
+      const tick_type ns = tv_nsec + tv_sec * ticks_per_second;
+      const tick_type xns = rhs.tv_nsec + rhs.tv_sec * ticks_per_second;
+      return ns == xns;
+    }
+  
+    bool operator!=(const system_time& rhs) const
+    {
+      return !(*this == rhs);
+    }
+  
+    bool operator<(const system_time& rhs) const
+    {
+      const tick_type ns = tv_nsec + tv_sec * ticks_per_second;
+      const tick_type xns = rhs.tv_nsec + rhs.tv_sec * ticks_per_second;
+      return ns < xns;
+    }
+  
+    bool operator<=(const system_time& rhs) const
+    {
+      return !(rhs < *this);
+    }
+  
+    bool operator>(const system_time& rhs) const
+    {
+      return rhs < *this;
+    }
+  
+    bool operator>=(const system_time& rhs) const
+    {
+      return !(*this < rhs);
+    }
+  
+    // arithmetic functions
+    nanoseconds operator-(const system_time& rhs) const
+    {
+      const tick_type ns = tv_nsec + tv_sec * ticks_per_second;
+      const tick_type xns = rhs.tv_nsec + rhs.tv_sec * ticks_per_second;
+      return nanoseconds(ns - xns);
+    }
+  
+    template<typename Duration>
+      system_time
+      operator+(const Duration& td) const;
+  
+    template<typename Duration>
+      system_time&
+      operator+=(const Duration& td);
+  
+    template<typename Duration>
+      system_time
+      operator-(const Duration& td) const;
+  
+    template<typename Duration>
+      system_time&
+      operator-=(const Duration& td);
+  
+  public:
+    time_t tv_sec;
+    long tv_nsec;
+  };
+  
+  // non-member functions
+  system_time
+  get_system_time();
+  
+  template<typename Duration>
+    system_time
+    operator+(const Duration& td, const system_time& rhs);
+  
+  template<class LhsDuration, class RhsDuration>
+    bool
+    operator==(const LhsDuration& lhs, const RhsDuration& rhs);
+  template<class LhsDuration, class RhsDuration>
+    bool
+    operator!=(const LhsDuration& lhs, const RhsDuration& rhs);
+  
+  template<class LhsDuration, class RhsDuration>
+     bool
+     operator<(const LhsDuration& lhs, const RhsDuration& rhs);
+  template<class LhsDuration, class RhsDuration>
+    bool
+    operator<=(const LhsDuration& lhs, const RhsDuration& rhs);
+  template<class LhsDuration, class RhsDuration>
+    bool
+    operator>(const LhsDuration& lhs, const RhsDuration& rhs);
+  template<class LhsDuration, class RhsDuration>
+    bool
+    operator>=(const LhsDuration& lhs, const RhsDuration& rhs);
+  
+  template<typename LhsDuration, typename RhsDuration>
+    struct __finest_duration;
+  
+  template<class LhsDuration, class RhsDuration>
+    typename __finest_duration<LhsDuration, RhsDuration>::type
+    operator+(const LhsDuration& lhs, const RhsDuration& rhs);
+  template<class LhsDuration, class RhsDuration>
+    typename __finest_duration<LhsDuration, RhsDuration>::type
+    operator-(const LhsDuration& lhs, const RhsDuration& rhs);
+  
+  template<class Duration>
+    Duration
+    operator*(Duration lhs, long rhs);
+  template<class Duration>
+    Duration
+    operator*(long lhs, Duration rhs);
+  
+  template<class Duration>
+    Duration
+    operator/(Duration lhs, long rhs);
+
+}
+
+#endif /* _GLIBCXX_DATE_TIME */
Index: include/Makefile.am
===================================================================
--- include/Makefile.am	(revisão 133071)
+++ include/Makefile.am	(cópia de trabalho)
@@ -33,6 +33,7 @@
 	${std_srcdir}/bitset \
 	${std_srcdir}/c++0x_warning.h \
 	${std_srcdir}/complex \
+	${std_srcdir}/date_time \
 	${std_srcdir}/deque \
 	${std_srcdir}/fstream \
 	${std_srcdir}/functional \
Index: config/abi/pre/gnu.ver
===================================================================
--- config/abi/pre/gnu.ver	(revisão 133071)
+++ config/abi/pre/gnu.ver	(cópia de trabalho)
@@ -803,6 +803,9 @@
     _ZNSt12system_errorC*;
 
     _ZNKSt4hashISt10error_codeEclES0_;
+    
+    # date_time
+    _ZSt15get_system_timev;
 
 } GLIBCXX_3.4.10;
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [c++0x] <date_time> implementation, take 2
  2008-03-10  4:17 [c++0x] <date_time> implementation, take 2 Pedro Lamarão
@ 2008-03-10 12:41 ` Paolo Carlini
  2008-03-11  3:15   ` Pedro Lamarão
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2008-03-10 12:41 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: libstdc++, gcc-patches

Thanks Pedro,

I have some additional general comments, sorry for not telling you at
once. I'm sure that next time everything will be *much* faster ;)
> Here goes. The patch was generated with svn diff.
>
> It defines get_system_time using std::time; we can add support for
> more precise stuff later.
Seems a good idea, as a nit please call with std::time.
> Attached in a tarball is a testsuite for std::nanoseconds and
> std::system_time.
Great. In general we are always using -std=gnu++0x, in the tests.
> 2008-03-10  Pedro Lamarão  <pedro.lamarao@gmail.com>
>
>     * include/std/date_time: new file.
>     * src/date_time.cpp: new file.
>     * config/abi/pre/gnu.ver: get_system_time is a new symbol
>     in version GLIBCXX_3.4.11.
>     * include/Makefile.am: add date_time in std headers.
>     * src/Makefile.am: add date_time.cc to source files.
It looks like definitions are missing for the various static constants.
Also, remember that all the symbols used in the implementation must be
"uglified", typically with double underscore in front or single in case
of types, template parameters, have a look to the existing code for
examples...

Paolo.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [c++0x] <date_time> implementation, take 2
  2008-03-10 12:41 ` Paolo Carlini
@ 2008-03-11  3:15   ` Pedro Lamarão
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Lamarão @ 2008-03-11  3:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++

Paolo Carlini escreveu:

> It looks like definitions are missing for the various static constants.

I looked for the mangled name for get_system_time using nm and grep on 
the shared object.

I can't find the string ticks_per_second and friends using this trick.

I notice these static constants are defined inline; will they every 
produce a symbol in the shared object?
How can I find it's name?

--
  P.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-11  3:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-10  4:17 [c++0x] <date_time> implementation, take 2 Pedro Lamarão
2008-03-10 12:41 ` Paolo Carlini
2008-03-11  3:15   ` Pedro Lamarão

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).