Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FourCC.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLIO/src/ICLIO/FourCC.h                               **
00010 ** Module : ICLIO                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/BasicTypes.h>
00034 #include <ICLUtils/Exception.h>
00035 #include <string>
00036 #include <iostream>
00037 
00038 namespace icl{
00039   namespace io{
00040     
00042 
00043     class FourCC{
00044       icl32s key; 
00045         
00046       public:
00048       FourCC():key(0){}
00049       
00051       FourCC(icl32s key):key(key){} 
00052       
00054       FourCC(const std::string &key){
00055         init(key);
00056       }
00057       
00059       FourCC(const char *key){
00060         init(key);
00061       }
00062   
00064       void init(const std::string &key) throw (utils::ICLException){
00065         if(key.length() != 4) throw utils::ICLException("FourCC::FourCC(string): invalid fourcc code " + key);
00066         if(key == "null") this->key = 0;
00067         else this->key = (((icl32u)(key[0])<<0)|((icl32u)(key[1])<<8)|((icl32u)(key[2])<<16)|((icl32u)(key[3])<<24));
00068       }
00069       
00071       inline FourCC &operator=(icl32s key) { return *this=FourCC(key); }
00072   
00074       inline FourCC &operator=(const std::string &key) { return *this=FourCC(key); }
00075       
00077       std::string asString() const {
00078         if(!key) return "null";
00079         int tmp[2] = {key,0};
00080         return std::string((char*)tmp);
00081       }
00082       
00084       icl32s asInt() const {
00085         return key;
00086       }
00087       
00089       operator bool() { return key != 0; }
00090   
00092       operator int() { return asInt(); }
00093     };
00094   
00096     inline std::ostream &operator<<(std::ostream &stream, const FourCC &fourCC){
00097       return stream << "FourCC(" << fourCC.asString() << ")" << std::endl;
00098     }
00099   
00100   } // namespace io
00101 }
00102 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines