summaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/tests/container_test_util.cc
blob: a53d351e0c1aa9a82695dc69a6ec216dc1b2375f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

#include "mojo/public/cpp/bindings/tests/container_test_util.h"

namespace mojo {

size_t CopyableType::num_instances_ = 0;
size_t MoveOnlyType::num_instances_ = 0;

CopyableType::CopyableType() : copied_(false), ptr_(this) {
  num_instances_++;
}

CopyableType::CopyableType(const CopyableType& other)
    : copied_(true), ptr_(other.ptr()) {
  num_instances_++;
}

CopyableType& CopyableType::operator=(const CopyableType& other) {
  copied_ = true;
  ptr_ = other.ptr();
  return *this;
}

CopyableType::~CopyableType() {
  num_instances_--;
}

MoveOnlyType::MoveOnlyType() : moved_(false), ptr_(this) {
  num_instances_++;
}

MoveOnlyType::MoveOnlyType(MoveOnlyType&& other)
    : moved_(true), ptr_(other.ptr()) {
  num_instances_++;
}

MoveOnlyType& MoveOnlyType::operator=(MoveOnlyType&& other) {
  moved_ = true;
  ptr_ = other.ptr();
  return *this;
}

MoveOnlyType::~MoveOnlyType() {
  num_instances_--;
}

}  // namespace mojo