00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2006 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #include "status-code.h" 00022 #include <string> 00023 #include <ostream> 00024 00025 namespace ns3 { 00026 00027 StatusCode::StatusCode () 00028 {} 00029 void 00030 StatusCode::SetSuccess (void) 00031 { 00032 m_code = 0; 00033 } 00034 void 00035 StatusCode::SetFailure (void) 00036 { 00037 m_code = 1; 00038 } 00039 00040 bool 00041 StatusCode::IsSuccess (void) const 00042 { 00043 return (m_code == 0)?true:false; 00044 } 00045 uint32_t 00046 StatusCode::GetSerializedSize (void) const 00047 { 00048 return 2; 00049 } 00050 Buffer::Iterator 00051 StatusCode::Serialize (Buffer::Iterator start) const 00052 { 00053 start.WriteHtonU16 (m_code); 00054 return start; 00055 } 00056 Buffer::Iterator 00057 StatusCode::Deserialize (Buffer::Iterator start) 00058 { 00059 m_code = start.ReadNtohU16 (); 00060 return start; 00061 } 00062 00063 std::ostream & 00064 operator << (std::ostream &os, const StatusCode &code) 00065 { 00066 if (code.IsSuccess ()) 00067 { 00068 os << "success"; 00069 } 00070 else 00071 { 00072 os << "failure"; 00073 } 00074 return os; 00075 } 00076 00077 } // namespace ns3