Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 22 | #include "nfd-constants.hpp" |
| 23 | #include <iostream> |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 24 | #include <map> |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace nfd { |
| 28 | |
| 29 | std::ostream& |
| 30 | operator<<(std::ostream& os, FaceScope faceScope) |
| 31 | { |
| 32 | switch (faceScope) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 33 | case FACE_SCOPE_NONE: |
| 34 | return os << "none"; |
| 35 | case FACE_SCOPE_NON_LOCAL: |
| 36 | return os << "non-local"; |
| 37 | case FACE_SCOPE_LOCAL: |
| 38 | return os << "local"; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 39 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 40 | return os << static_cast<unsigned>(faceScope); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | std::ostream& |
| 44 | operator<<(std::ostream& os, FacePersistency facePersistency) |
| 45 | { |
| 46 | switch (facePersistency) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 47 | case FACE_PERSISTENCY_NONE: |
| 48 | return os << "none"; |
| 49 | case FACE_PERSISTENCY_PERSISTENT: |
| 50 | return os << "persistent"; |
| 51 | case FACE_PERSISTENCY_ON_DEMAND: |
| 52 | return os << "on-demand"; |
| 53 | case FACE_PERSISTENCY_PERMANENT: |
| 54 | return os << "permanent"; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 55 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 56 | return os << static_cast<unsigned>(facePersistency); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | std::ostream& |
| 60 | operator<<(std::ostream& os, LinkType linkType) |
| 61 | { |
| 62 | switch (linkType) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 63 | case LINK_TYPE_NONE: |
| 64 | return os << "none"; |
| 65 | case LINK_TYPE_POINT_TO_POINT: |
| 66 | return os << "point-to-point"; |
| 67 | case LINK_TYPE_MULTI_ACCESS: |
| 68 | return os << "multi-access"; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 69 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 70 | return os << static_cast<unsigned>(linkType); |
| 71 | } |
| 72 | |
| 73 | std::ostream& |
| 74 | operator<<(std::ostream& os, FaceEventKind faceEventKind) |
| 75 | { |
| 76 | switch (faceEventKind) { |
| 77 | case FACE_EVENT_NONE: |
| 78 | return os << "none"; |
| 79 | case FACE_EVENT_CREATED: |
| 80 | return os << "created"; |
| 81 | case FACE_EVENT_DESTROYED: |
| 82 | return os << "destroyed"; |
| 83 | case FACE_EVENT_UP: |
| 84 | return os << "up"; |
| 85 | case FACE_EVENT_DOWN: |
| 86 | return os << "down"; |
| 87 | } |
| 88 | return os << static_cast<unsigned>(faceEventKind); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | std::ostream& |
| 92 | operator<<(std::ostream& os, RouteOrigin routeOrigin) |
| 93 | { |
| 94 | switch (routeOrigin) { |
| 95 | case ROUTE_ORIGIN_NONE: |
| 96 | return os << "none"; |
| 97 | case ROUTE_ORIGIN_APP: |
| 98 | return os << "app"; |
| 99 | case ROUTE_ORIGIN_AUTOREG: |
| 100 | return os << "autoreg"; |
| 101 | case ROUTE_ORIGIN_CLIENT: |
| 102 | return os << "client"; |
| 103 | case ROUTE_ORIGIN_AUTOCONF: |
| 104 | return os << "autoconf"; |
| 105 | case ROUTE_ORIGIN_NLSR: |
| 106 | return os << "nlsr"; |
| 107 | case ROUTE_ORIGIN_STATIC: |
| 108 | return os << "static"; |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 109 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 110 | return os << static_cast<unsigned>(routeOrigin); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | std::ostream& |
| 114 | operator<<(std::ostream& os, RouteFlags routeFlags) |
| 115 | { |
| 116 | if (routeFlags == ROUTE_FLAGS_NONE) { |
| 117 | return os << "none"; |
| 118 | } |
| 119 | |
| 120 | bool isFirst = true; |
| 121 | auto printToken = [&os, &isFirst] (const std::string& token) { |
| 122 | if (isFirst) { |
| 123 | isFirst = false; |
| 124 | } |
| 125 | else { |
| 126 | os << '|'; |
| 127 | } |
| 128 | os << token; |
| 129 | }; |
| 130 | |
| 131 | static const std::map<RouteFlags, std::string> knownBits = { |
| 132 | {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"}, |
| 133 | {ROUTE_FLAG_CAPTURE, "capture"}}; |
| 134 | for (const auto& pair : knownBits) { |
| 135 | RouteFlags bit = ROUTE_FLAGS_NONE; |
| 136 | std::string token; |
| 137 | std::tie(bit, token) = pair; |
| 138 | |
| 139 | if ((routeFlags & bit) == 0) { |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | printToken(token); |
| 144 | routeFlags = static_cast<RouteFlags>(routeFlags & ~bit); |
| 145 | } |
| 146 | |
| 147 | if (routeFlags != 0) { |
| 148 | printToken("0x"); |
| 149 | std::ios_base::fmtflags oldFmt = os.flags(); |
| 150 | os << std::hex << std::nouppercase |
| 151 | << static_cast<unsigned>(routeFlags); |
| 152 | os.flags(oldFmt); |
| 153 | } |
| 154 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 155 | return os; |
| 156 | } |
| 157 | |
| 158 | } // namespace nfd |
| 159 | } // namespace ndn |