Skip to content

Commit

Permalink
COMP: Add itkIRCommon.h includes
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed May 28, 2024
1 parent bb698bd commit cbad1fc
Show file tree
Hide file tree
Showing 38 changed files with 10,179 additions and 21 deletions.
75 changes: 75 additions & 0 deletions include/IRException.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// -*- Mode: c++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: t -*-
// NOTE: the first line of this file sets up source code indentation rules
// for Emacs; it is also a hint to anyone modifying this file.

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


// File : the_exception.hxx
// Author : Pavel A. Koshevoy
// Created : Sun Sep 24 18:06:00 MDT 2006
// Copyright : (C) 2004-2008 University of Utah
// License : GPLv2
// Description : an exception convenience class

#ifndef THE_EXCEPTION_HXX_
#define THE_EXCEPTION_HXX_

// system includes:
#include <exception>
#include <string>
#include <sstream>


//----------------------------------------------------------------
// the_exception_t
//
class the_exception_t : public std::exception
{
public:
the_exception_t(const char * description = NULL,
const char * file = NULL,
const unsigned int & line = 0)
{
std::ostringstream os;

if (file != NULL)
{
os << file << ':' << line << " -- ";
}

if (description != NULL)
{
os << description;
}

what_ = os.str();
}

virtual ~the_exception_t() throw ()
{}

// virtual:
const char * what() const throw()
{ return what_.c_str(); }

// data:
std::string what_;
};


#endif // THE_EXCEPTION_HXX_
169 changes: 169 additions & 0 deletions include/IRLog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// -*- Mode: c++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: t -*-
// NOTE: the first line of this file sets up source code indentation rules
// for Emacs; it is also a hint to anyone modifying this file.

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


// File : the_log.hxx
// Author : Pavel A. Koshevoy
// Created : Fri Mar 23 10:34:12 MDT 2007
// Copyright : (C) 2004-2008 University of Utah
// License : GPLv2
// Description : A text log object -- behaves almost like a std::ostream.

#ifndef THE_LOG_HXX_
#define THE_LOG_HXX_

// system includes:
#include <iosfwd>
#include <iostream>
#include <iomanip>
#include <sstream>

// local includes:
#include "IRMutexInterface.h"
#include "itkIRUtils.h"


//----------------------------------------------------------------
// the_log_t
//
class the_log_t
{
protected:
void log_no_lock(std::ostream & (*f)(std::ostream &));

public:
the_log_t();
virtual ~the_log_t();

virtual the_log_t &
operator << (std::ostream & (*f)(std::ostream &));

template <typename data_t>
the_log_t &
operator << (const data_t & data)
{
the_lock_t<the_mutex_interface_t> lock(mutex_);
line_ << data;
return *this;
}

std::streamsize precision();
std::streamsize precision(std::streamsize n);

std::ios::fmtflags flags() const;
std::ios::fmtflags flags(std::ios::fmtflags fmt);

void setf(std::ios::fmtflags fmt);
void setf(std::ios::fmtflags fmt, std::ios::fmtflags msk);
void unsetf(std::ios::fmtflags fmt);

void copyfmt(std::ostream & ostm);

std::ostringstream line_;
mutable the_mutex_interface_t * mutex_;
};


//----------------------------------------------------------------
// the_null_log_t
//
class the_null_log_t : public the_log_t
{
public:
// virtual:
the_log_t & operator << (std::ostream & (*)(std::ostream &))
{ return *this; }

template <typename data_t>
the_log_t & operator << (const data_t &)
{ return *this; }
};

//----------------------------------------------------------------
// the_stream_log_t
//
class the_stream_log_t : public the_log_t
{
public:
the_stream_log_t(std::ostream & ostm):
ostm_(ostm)
{}

// virtual:
the_log_t & operator << (std::ostream & (*f)(std::ostream &))
{
the_lock_t<the_mutex_interface_t> lock(the_log_t::mutex_);
the_log_t::log_no_lock(f);
ostm_ << the_log_t::line_.str();
the_log_t::line_.str("");
return *this;
}

template <typename data_t>
the_log_t & operator << (const data_t & data)
{ return the_log_t::operator << (data); }

std::ostream & ostm_;
};


//----------------------------------------------------------------
// the_text_log_t
//
class the_text_log_t : public the_log_t
{
public:
// virtual:
the_log_t & operator << (std::ostream & (*f)(std::ostream &))
{
the_lock_t<the_mutex_interface_t> lock(the_log_t::mutex_);
the_log_t::log_no_lock(f);
text_ += the_log_t::line_.str();
the_log_t::line_.str("");
return *this;
}

template <typename data_t>
the_log_t & operator << (const data_t & data)
{ return the_log_t::operator << (data); }

inline std::string text()
{ return text_; }

std::string text_;
};

//----------------------------------------------------------------
// null_log
//
extern the_null_log_t * null_log();

//----------------------------------------------------------------
// cerr_log
//
extern the_stream_log_t * cerr_log();

//----------------------------------------------------------------
// cout_log
//
extern the_stream_log_t * cout_log();


#endif // THE_LOG_HXX_
76 changes: 76 additions & 0 deletions include/IRMutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -*- Mode: c++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: t -*-
// NOTE: the first line of this file sets up source code indentation rules
// for Emacs; it is also a hint to anyone modifying this file.

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


// File : the_boost_mutex.hxx
// Author : Pavel A. Koshevoy
// Created : Sat Oct 25 12:33:43 MDT 2008
// Copyright : (C) 2004-2008 University of Utah
// License : GPLv2
// Description : A thin wrapper for Boost mutex class.

#ifndef THE_BOOST_MUTEX_HXX_
#define THE_BOOST_MUTEX_HXX_

// local includes:
#include "thread/the_mutex_interface.hxx"

// Boost includes:
#include <boost/thread/mutex.hpp>


//----------------------------------------------------------------
// the_boost_mutex_t
//
class the_boost_mutex_t : public the_mutex_interface_t
{
public:
the_boost_mutex_t();

// the destructor is protected on purpose,
// see delete_this for details:
virtual ~the_boost_mutex_t();

// In order to avoid memory management problems with shared libraries,
// whoever provides this interface instance (via it's creator), has to
// provide a way to delete the instance as well. This will avoid
// issues with multiple-instances of C runtime libraries being
// used by the app and whatever libraries it links against that
// either use or provide this interface:
virtual void delete_this();

// the creation method:
static the_mutex_interface_t * create();

// virtual:
void lock();

// virtual:
void unlock();

// virtual:
bool try_lock();

private:
boost::mutex mutex_;
};


#endif // THE_BOOST_MUTEX_HXX_
74 changes: 74 additions & 0 deletions include/IRMutexInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// -*- Mode: c++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: t -*-
// NOTE: the first line of this file sets up source code indentation rules
// for Emacs; it is also a hint to anyone modifying this file.

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


// File : the_mutex_interface.hxx
// Author : Pavel A. Koshevoy
// Created : Sun Feb 18 16:12:00 MST 2007
// Copyright : (C) 2004-2008 University of Utah
// License : GPLv2
// Description : An abstract mutex class interface.

#ifndef THE_MUTEX_INTERFACE_HXX_
#define THE_MUTEX_INTERFACE_HXX_


//----------------------------------------------------------------
// the_mutex_interface_t
//
class the_mutex_interface_t
{
protected:
// the destructor is protected on purpose,
// see delete_this for details:
virtual ~the_mutex_interface_t();

public:
// In order to avoid memory management problems with shared libraries,
// whoever provides this interface instance (via it's creator), has to
// provide a way to delete the instance as well. This will avoid
// issues with multiple-instances of C runtime libraries being
// used by the app and whatever libraries it links against that
// either use or provide this interface:
virtual void delete_this() = 0;

// mutex controls:
virtual void lock() = 0;
virtual void unlock() = 0;
virtual bool try_lock() = 0;

//----------------------------------------------------------------
// creator_t
//
typedef the_mutex_interface_t *(*creator_t)();

// specify a thread creation method:
static void set_creator(creator_t creator);

// create a new instance of a thread:
static the_mutex_interface_t * create();

protected:
// an abstract mutex creator:
static creator_t creator_;
};


#endif // THE_MUTEX_INTERFACE_HXX_
Loading

0 comments on commit cbad1fc

Please sign in to comment.