I don't understand exactly - where did you hope see realization of RAII here
? )
In this class we acquire only one resource - n-bytes of heap memory.
If we don't get it, there are nothing to release.
BTW, I disagree with construction Message object from stream.
From my point of view construction is operation which intended only for
setup of object's initial state.

I see two problems here:
1. we can't allocate memory for text (bad_alloc), we should revert input
stream to the beginning  of message (state which were before we began read
message)
2. we can't read any information after memory was allocated (stream fault),
we should release memory and stop read.

I try to solve this puzzle.

 

  _____  

From: Ivan Sidarau [mailto:notifications@github.com] 
Sent: Sunday, November 03, 2013 3:11 PM
To: sidorovis/cpp_craft_1013
Cc: PeterMoroz
Subject: Re: [cpp_craft_1013] all previous tasks in one pull request (#132)

 

In solutions/peter_moroz/puzzles-2/sources/common/Message.h:

> +public:
> +  Message() : type_(0), time_(0) {}
> +
> +  MessageType type() const { return type_; }
> +  boost::uint32_t time() const { return time_; }
> +
> +  size_t GetTotalSize() const {
> +    return (sizeof(type_) + sizeof(time_) + text_.size());
> +  }
> +  void ReadFrom(std::istream& is);
> +  void WriteTo(std::ostream& os) const;
> +
> +private:
> +  MessageType type_;
> +  boost::uint32_t time_;
> +  std::string text_;

i hoped to see realization of RAII idiom here :) but, yes. it is possible to
do with storing into string and length of such string

-
Reply to this email directly or view
<https://github.com/sidorovis/cpp_craft_1013/pull/132/files#r7390592>  it on
GitHub.
<https://github.com/notifications/beacon/O7y4LvL-5wBGMo5Tflvq1m-4ZaL5V540nNJ
OdW5qhqShQxrRNzG5KVj-EtvAYB7R.gif>