MyGUI  3.2.0
MyGUI_FlowDirection.h
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #ifndef __MYGUI_FLOW_DIRECTION_H__
00023 #define __MYGUI_FLOW_DIRECTION_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 #include <string>
00027 
00028 namespace MyGUI
00029 {
00030 
00031     struct MYGUI_EXPORT FlowDirection
00032     {
00033         enum Enum
00034         {
00035             LeftToRight,
00036             RightToLeft,
00037             TopToBottom,
00038             BottomToTop,
00039             MAX
00040         };
00041 
00042         FlowDirection(Enum _value = LeftToRight) :
00043             value(_value)
00044         {
00045         }
00046 
00047         static FlowDirection parse(const std::string& _value)
00048         {
00049             FlowDirection type;
00050             int value = 0;
00051             while (true)
00052             {
00053                 const char* name = type.getValueName(value);
00054                 if (strcmp(name, "") == 0 || name == _value) break;
00055                 value++;
00056             }
00057             type.value = (Enum)value;
00058             return type;
00059         }
00060 
00061         bool isHorizontal() const
00062         {
00063             return value == LeftToRight || value == RightToLeft;
00064         }
00065 
00066         bool isVertical() const
00067         {
00068             return !isHorizontal();
00069         }
00070 
00071         friend bool operator == (FlowDirection const& a, FlowDirection const& b)
00072         {
00073             return a.value == b.value;
00074         }
00075 
00076         friend bool operator != (FlowDirection const& a, FlowDirection const& b)
00077         {
00078             return a.value != b.value;
00079         }
00080 
00081         friend std::ostream& operator << ( std::ostream& _stream, const FlowDirection&  _value )
00082         {
00083             _stream << _value.getValueName(_value.value);
00084             return _stream;
00085         }
00086 
00087         friend std::istream& operator >> ( std::istream& _stream, FlowDirection&  _value )
00088         {
00089             std::string value;
00090             _stream >> value;
00091             _value = parse(value);
00092             return _stream;
00093         }
00094 
00095         std::string print() const
00096         {
00097             return getValueName(value);
00098         }
00099 
00100     private:
00101         const char* getValueName(int _index) const
00102         {
00103             static const char* values[MAX + 1] = { "LeftToRight", "RightToLeft", "TopToBottom", "BottomToTop", "" };
00104             return values[(_index < MAX && _index >= 0) ? _index : MAX];
00105         }
00106 
00107     private:
00108         Enum value;
00109     };
00110 
00111 } // namespace MyGUI
00112 
00113 #endif // __MYGUI_FLOW_DIRECTION_H__