source: to-imperative/trunk/runtime/rf_channel.ih @ 1156

Last change on this file since 1156 was 1156, checked in by pooh, 17 years ago
  • Do not close already opened channels.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.3 KB
Line 
1#ifndef __rf_channel_ih__
2#define __rf_channel_ih__
3
4#include "rf_channel.hh"
5#include "rf_object.ih"
6#include "rf_expr.ih"
7
8#include <typeinfo>
9
10namespace rftype
11{
12
13inline Channel::Channel (FILE* _fp /* = null */) :
14  fp (_fp)
15{
16  was_opened = (fp != null) ? true : false;
17}
18
19inline Channel::Channel (Channel const& _channel) :
20  Object (),
21  fp (_channel.fp)
22{}
23
24inline Channel::~Channel ()
25{
26  if (!was_opened) close();
27}
28
29inline Channel& Channel::operator = (Channel const& _channel)
30{
31  if (this != &_channel) {
32    this->~Channel();
33    new(this) Channel(_channel);
34  }
35  return self;
36}
37
38inline unsigned Channel::get_type () const
39{
40  return reg.get_type();
41}
42
43//
44// FIXME: Return proper hash value
45inline uint32_t Channel::hash () const
46{
47  return 0;
48}
49
50inline bool Channel::operator == (Object const& _obj) const
51{
52  try {
53    Channel const& ch = dynamic_cast<Channel const&>(_obj);
54    return fp == ch.fp;
55  } catch (std::bad_cast&) {
56    return false;
57  }
58}
59
60inline bool Channel::open (char const* _fname, char const* _mode)
61{
62  if (fp != 0) fclose(fp);
63  fp = fopen(_fname, _mode);
64  return fp != null ? true : false;
65}
66
67inline void Channel::close ()
68{
69  if (fp != 0) fclose(fp);
70}
71
72inline FILE* Channel::get_fp () const
73{
74  return fp;
75}
76
77}
78
79#endif // __rf_channel_ih__
Note: See TracBrowser for help on using the repository browser.