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"; |
| 39 | default: |
| 40 | return os << static_cast<unsigned>(faceScope); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 41 | } |
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"; |
| 56 | default: |
| 57 | return os << static_cast<unsigned>(facePersistency); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 58 | } |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | std::ostream& |
| 62 | operator<<(std::ostream& os, LinkType linkType) |
| 63 | { |
| 64 | switch (linkType) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 65 | case LINK_TYPE_NONE: |
| 66 | return os << "none"; |
| 67 | case LINK_TYPE_POINT_TO_POINT: |
| 68 | return os << "point-to-point"; |
| 69 | case LINK_TYPE_MULTI_ACCESS: |
| 70 | return os << "multi-access"; |
| 71 | default: |
| 72 | return os << static_cast<unsigned>(linkType); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 73 | } |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | std::ostream& |
| 77 | operator<<(std::ostream& os, RouteOrigin routeOrigin) |
| 78 | { |
| 79 | switch (routeOrigin) { |
| 80 | case ROUTE_ORIGIN_NONE: |
| 81 | return os << "none"; |
| 82 | case ROUTE_ORIGIN_APP: |
| 83 | return os << "app"; |
| 84 | case ROUTE_ORIGIN_AUTOREG: |
| 85 | return os << "autoreg"; |
| 86 | case ROUTE_ORIGIN_CLIENT: |
| 87 | return os << "client"; |
| 88 | case ROUTE_ORIGIN_AUTOCONF: |
| 89 | return os << "autoconf"; |
| 90 | case ROUTE_ORIGIN_NLSR: |
| 91 | return os << "nlsr"; |
| 92 | case ROUTE_ORIGIN_STATIC: |
| 93 | return os << "static"; |
| 94 | default: |
| 95 | return os << static_cast<unsigned>(routeOrigin); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | std::ostream& |
| 100 | operator<<(std::ostream& os, RouteFlags routeFlags) |
| 101 | { |
| 102 | if (routeFlags == ROUTE_FLAGS_NONE) { |
| 103 | return os << "none"; |
| 104 | } |
| 105 | |
| 106 | bool isFirst = true; |
| 107 | auto printToken = [&os, &isFirst] (const std::string& token) { |
| 108 | if (isFirst) { |
| 109 | isFirst = false; |
| 110 | } |
| 111 | else { |
| 112 | os << '|'; |
| 113 | } |
| 114 | os << token; |
| 115 | }; |
| 116 | |
| 117 | static const std::map<RouteFlags, std::string> knownBits = { |
| 118 | {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"}, |
| 119 | {ROUTE_FLAG_CAPTURE, "capture"}}; |
| 120 | for (const auto& pair : knownBits) { |
| 121 | RouteFlags bit = ROUTE_FLAGS_NONE; |
| 122 | std::string token; |
| 123 | std::tie(bit, token) = pair; |
| 124 | |
| 125 | if ((routeFlags & bit) == 0) { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | printToken(token); |
| 130 | routeFlags = static_cast<RouteFlags>(routeFlags & ~bit); |
| 131 | } |
| 132 | |
| 133 | if (routeFlags != 0) { |
| 134 | printToken("0x"); |
| 135 | std::ios_base::fmtflags oldFmt = os.flags(); |
| 136 | os << std::hex << std::nouppercase |
| 137 | << static_cast<unsigned>(routeFlags); |
| 138 | os.flags(oldFmt); |
| 139 | } |
| 140 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 141 | return os; |
| 142 | } |
| 143 | |
| 144 | } // namespace nfd |
| 145 | } // namespace ndn |