OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/public/cpp/bindings/lib/validator_chain.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 namespace mojo { |
| 10 namespace internal { |
| 11 |
| 12 ValidatorChain::ValidatorChain(MessageReceiver* sink) : sink_(sink) { |
| 13 } |
| 14 |
| 15 ValidatorChain::ValidatorChain(RValue other) : sink_(other.object->sink_) { |
| 16 other.object->sink_ = NULL; |
| 17 validators_.swap(other.object->validators_); |
| 18 } |
| 19 |
| 20 ValidatorChain& ValidatorChain::operator=(RValue other) { |
| 21 std::swap(sink_, other.object->sink_); |
| 22 validators_.swap(other.object->validators_); |
| 23 return *this; |
| 24 } |
| 25 |
| 26 ValidatorChain::~ValidatorChain() { |
| 27 for (std::vector<MessageValidator*>::iterator iter = validators_.begin(); |
| 28 iter != validators_.end(); |
| 29 ++iter) { |
| 30 delete *iter; |
| 31 } |
| 32 } |
| 33 |
| 34 ValidatorChain& ValidatorChain::Append(MessageValidator* validator) { |
| 35 if (!validators_.empty()) |
| 36 validators_.back()->set_next(validator); |
| 37 validators_.push_back(validator); |
| 38 |
| 39 return *this; |
| 40 } |
| 41 |
| 42 ValidatorChain& ValidatorChain::Append(NoValidator* validator) { |
| 43 delete validator; |
| 44 return *this; |
| 45 } |
| 46 |
| 47 MessageReceiver* ValidatorChain::GetHead() { |
| 48 assert(sink_); |
| 49 |
| 50 if (validators_.empty()) |
| 51 return sink_; |
| 52 |
| 53 validators_.back()->set_next(sink_); |
| 54 return validators_.front(); |
| 55 } |
| 56 |
| 57 } // namespace internal |
| 58 } // namespace mojo |
OLD | NEW |