Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 56bd3ee | 2017-02-26 16:05:16 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 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" |
Davide Pesavento | 56bd3ee | 2017-02-26 16:05:16 -0500 | [diff] [blame^] | 23 | |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 24 | #include <iostream> |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 25 | #include <map> |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace nfd { |
| 29 | |
| 30 | std::ostream& |
| 31 | operator<<(std::ostream& os, FaceScope faceScope) |
| 32 | { |
| 33 | switch (faceScope) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 34 | case FACE_SCOPE_NONE: |
| 35 | return os << "none"; |
| 36 | case FACE_SCOPE_NON_LOCAL: |
| 37 | return os << "non-local"; |
| 38 | case FACE_SCOPE_LOCAL: |
| 39 | return os << "local"; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 40 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 41 | return os << static_cast<unsigned>(faceScope); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | std::ostream& |
| 45 | operator<<(std::ostream& os, FacePersistency facePersistency) |
| 46 | { |
| 47 | switch (facePersistency) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 48 | case FACE_PERSISTENCY_NONE: |
| 49 | return os << "none"; |
| 50 | case FACE_PERSISTENCY_PERSISTENT: |
| 51 | return os << "persistent"; |
| 52 | case FACE_PERSISTENCY_ON_DEMAND: |
| 53 | return os << "on-demand"; |
| 54 | case FACE_PERSISTENCY_PERMANENT: |
| 55 | return os << "permanent"; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 56 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 57 | return os << static_cast<unsigned>(facePersistency); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | std::ostream& |
| 61 | operator<<(std::ostream& os, LinkType linkType) |
| 62 | { |
| 63 | switch (linkType) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 64 | case LINK_TYPE_NONE: |
| 65 | return os << "none"; |
| 66 | case LINK_TYPE_POINT_TO_POINT: |
| 67 | return os << "point-to-point"; |
| 68 | case LINK_TYPE_MULTI_ACCESS: |
| 69 | return os << "multi-access"; |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 70 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 71 | return os << static_cast<unsigned>(linkType); |
| 72 | } |
| 73 | |
| 74 | std::ostream& |
| 75 | operator<<(std::ostream& os, FaceEventKind faceEventKind) |
| 76 | { |
| 77 | switch (faceEventKind) { |
| 78 | case FACE_EVENT_NONE: |
| 79 | return os << "none"; |
| 80 | case FACE_EVENT_CREATED: |
| 81 | return os << "created"; |
| 82 | case FACE_EVENT_DESTROYED: |
| 83 | return os << "destroyed"; |
| 84 | case FACE_EVENT_UP: |
| 85 | return os << "up"; |
| 86 | case FACE_EVENT_DOWN: |
| 87 | return os << "down"; |
| 88 | } |
| 89 | return os << static_cast<unsigned>(faceEventKind); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | std::ostream& |
| 93 | operator<<(std::ostream& os, RouteOrigin routeOrigin) |
| 94 | { |
| 95 | switch (routeOrigin) { |
| 96 | case ROUTE_ORIGIN_NONE: |
| 97 | return os << "none"; |
| 98 | case ROUTE_ORIGIN_APP: |
| 99 | return os << "app"; |
| 100 | case ROUTE_ORIGIN_AUTOREG: |
| 101 | return os << "autoreg"; |
| 102 | case ROUTE_ORIGIN_CLIENT: |
| 103 | return os << "client"; |
| 104 | case ROUTE_ORIGIN_AUTOCONF: |
| 105 | return os << "autoconf"; |
| 106 | case ROUTE_ORIGIN_NLSR: |
| 107 | return os << "nlsr"; |
| 108 | case ROUTE_ORIGIN_STATIC: |
| 109 | return os << "static"; |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 110 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 111 | return os << static_cast<unsigned>(routeOrigin); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | std::ostream& |
| 115 | operator<<(std::ostream& os, RouteFlags routeFlags) |
| 116 | { |
| 117 | if (routeFlags == ROUTE_FLAGS_NONE) { |
| 118 | return os << "none"; |
| 119 | } |
| 120 | |
| 121 | bool isFirst = true; |
| 122 | auto printToken = [&os, &isFirst] (const std::string& token) { |
| 123 | if (isFirst) { |
| 124 | isFirst = false; |
| 125 | } |
| 126 | else { |
| 127 | os << '|'; |
| 128 | } |
| 129 | os << token; |
| 130 | }; |
| 131 | |
| 132 | static const std::map<RouteFlags, std::string> knownBits = { |
| 133 | {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"}, |
| 134 | {ROUTE_FLAG_CAPTURE, "capture"}}; |
| 135 | for (const auto& pair : knownBits) { |
| 136 | RouteFlags bit = ROUTE_FLAGS_NONE; |
| 137 | std::string token; |
| 138 | std::tie(bit, token) = pair; |
| 139 | |
| 140 | if ((routeFlags & bit) == 0) { |
| 141 | continue; |
| 142 | } |
| 143 | |
| 144 | printToken(token); |
| 145 | routeFlags = static_cast<RouteFlags>(routeFlags & ~bit); |
| 146 | } |
| 147 | |
| 148 | if (routeFlags != 0) { |
| 149 | printToken("0x"); |
| 150 | std::ios_base::fmtflags oldFmt = os.flags(); |
| 151 | os << std::hex << std::nouppercase |
Davide Pesavento | 56bd3ee | 2017-02-26 16:05:16 -0500 | [diff] [blame^] | 152 | << static_cast<uint64_t>(routeFlags); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 153 | os.flags(oldFmt); |
| 154 | } |
| 155 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 156 | return os; |
| 157 | } |
| 158 | |
| 159 | } // namespace nfd |
| 160 | } // namespace ndn |