MyGUI  3.2.1
MyGUI_FlowDirection.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_FLOW_DIRECTION_H__
00008 #define __MYGUI_FLOW_DIRECTION_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 #include <string>
00012 
00013 namespace MyGUI
00014 {
00015 
00016     struct MYGUI_EXPORT FlowDirection
00017     {
00018         enum Enum
00019         {
00020             LeftToRight,
00021             RightToLeft,
00022             TopToBottom,
00023             BottomToTop,
00024             MAX
00025         };
00026 
00027         FlowDirection(Enum _value = LeftToRight) :
00028             mValue(_value)
00029         {
00030         }
00031 
00032         static FlowDirection parse(const std::string& _value)
00033         {
00034             FlowDirection type;
00035             int value = 0;
00036             while (true)
00037             {
00038                 const char* name = type.getValueName(value);
00039                 if (strcmp(name, "") == 0 || name == _value) break;
00040                 value++;
00041             }
00042             type.mValue = (Enum)value;
00043             return type;
00044         }
00045 
00046         bool isHorizontal() const
00047         {
00048             return mValue == LeftToRight || mValue == RightToLeft;
00049         }
00050 
00051         bool isVertical() const
00052         {
00053             return !isHorizontal();
00054         }
00055 
00056         friend bool operator == (FlowDirection const& a, FlowDirection const& b)
00057         {
00058             return a.mValue == b.mValue;
00059         }
00060 
00061         friend bool operator != (FlowDirection const& a, FlowDirection const& b)
00062         {
00063             return a.mValue != b.mValue;
00064         }
00065 
00066         friend std::ostream& operator << ( std::ostream& _stream, const FlowDirection&  _value )
00067         {
00068             _stream << _value.getValueName(_value.mValue);
00069             return _stream;
00070         }
00071 
00072         friend std::istream& operator >> ( std::istream& _stream, FlowDirection&  _value )
00073         {
00074             std::string value;
00075             _stream >> value;
00076             _value = parse(value);
00077             return _stream;
00078         }
00079 
00080         std::string print() const
00081         {
00082             return getValueName(mValue);
00083         }
00084 
00085         int getValue() const
00086         {
00087             return mValue;
00088         }
00089 
00090     private:
00091         const char* getValueName(int _index) const
00092         {
00093             static const char* values[MAX + 1] = { "LeftToRight", "RightToLeft", "TopToBottom", "BottomToTop", "" };
00094             return values[(_index < MAX && _index >= 0) ? _index : MAX];
00095         }
00096 
00097     private:
00098         Enum mValue;
00099     };
00100 
00101 } // namespace MyGUI
00102 
00103 #endif // __MYGUI_FLOW_DIRECTION_H__