/*-1* Copyright (c) 2012, 2013 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* substantially similar to the "NO WARRANTY" disclaimer below12* ("Disclaimer") and any redistribution must be conditioned upon13* including a substantially similar Disclaimer requirement for further14* binary redistribution.15*16* NO WARRANTY17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGES.28*29* Authors: Alan Somers (Spectra Logic Corporation)30*/3132/**33* \file guid.cc34*35* Implementation of the Guid class.36*/37#include <sys/cdefs.h>3839#include <stdlib.h>40#include <limits.h>41#include <inttypes.h>4243#include <iostream>44#include <string>4546#include "guid.h"47/*============================ Namespace Control =============================*/48using std::string;49namespace DevdCtl50{5152/*=========================== Class Implementations ==========================*/53/*----------------------------------- Guid -----------------------------------*/54Guid::Guid(const string &guidString)55{56if (guidString.empty()) {57m_GUID = INVALID_GUID;58} else {59/*60* strtoumax() returns zero on conversion failure61* which nicely matches our choice for INVALID_GUID.62*/63m_GUID = (uint64_t)strtoumax(guidString.c_str(), NULL, 0);64}65}6667std::ostream&68operator<< (std::ostream& out, Guid g)69{70if (g.IsValid())71out << (uint64_t)g;72else73out << "None";74return (out);75}7677} // namespace DevdCtl787980