summaryrefslogtreecommitdiff
path: root/src/CommonAPI/Address.cpp
blob: ca49cf4e4cb1c09b16cfbdce3d199943906a8326 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <sstream>

#include <CommonAPI/Address.hpp>

namespace CommonAPI {

Address::Address() {

}

Address::Address(const std::string &_address) {
    // TODO: handle error situation (_address is no valid CommonAPI address)
    setAddress(_address);
}

Address::Address(const std::string &_domain,
                 const std::string &_interface,
                 const std::string &_instance)
    : domain_(_domain),
      interface_(_interface),
      instance_(_instance) {
}

Address::Address(const Address &_source)
    : domain_(_source.domain_),
      interface_(_source.interface_),
      instance_(_source.instance_) {
}

Address::~Address() {
}

bool
Address::operator ==(const Address &_other) const {
    return (domain_ == _other.domain_ &&
            interface_ == _other.interface_ &&
            instance_ == _other.instance_);
}

bool
Address::operator !=(const Address &_other) const {
    return (domain_ != _other.domain_ ||
            interface_ != _other.interface_ ||
            instance_ != _other.instance_);
}

bool
Address::operator<(const Address &_other) const {
    if (domain_ < _other.domain_)
        return true;

    if (domain_ == _other.domain_) {
        if (interface_ < _other.interface_)
            return true;

        if (interface_ == _other.interface_) {
            if (instance_ < _other.instance_)
                return true;
        }
    }

    return false;
}

std::string
Address::getAddress() const {
    return (domain_ + ":" + interface_ + ":" + instance_);
}

void
Address::setAddress(const std::string &_address) {
    std::istringstream addressStream(_address);
    if (std::getline(addressStream, domain_, ':')) {
        if (std::getline(addressStream, interface_, ':')) {
            if(!std::getline(addressStream, instance_, ':')) {
                if(std::getline(addressStream, instance_)) {
                }
            }
        }
    }
}

const std::string &
Address::getDomain() const {
    return domain_;
}

void
Address::setDomain(const std::string &_domain) {
    domain_ = _domain;
}

const std::string &
Address::getInterface() const {
    return interface_;
}

void
Address::setInterface(const std::string &_interface) {
    interface_ = _interface;
}

const std::string &
Address::getInstance() const {
    return instance_;
}

void
Address::setInstance(const std::string &_instance) {
    instance_ = _instance;
}

std::ostream &
operator<<(std::ostream &_out, const Address &_address) {
    _out << _address.domain_
          << ":" << _address.interface_
          << ":" << _address.instance_;
    return _out;
}

} // namespace CommonAPI