From: Myun2 Date: Fri, 24 Dec 2010 13:29:23 +0000 (+0900) Subject: web/css_attributes.hpp: 新たにlexicalとして作り直し開始。とりあえずpadding X-Git-Tag: 20111130_shapeup_prev^2~159 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ae6d84a503a20b63fe61728bb83d3e17343f70c1;p=roast%2Froast.git web/css_attributes.hpp: 新たにlexicalとして作り直し開始。とりあえずpadding --- diff --git a/roast/include/roast/web/css_attributes.hpp b/roast/include/roast/web/css_attributes.hpp index 70003c1e..9d0ad129 100644 --- a/roast/include/roast/web/css_attributes.hpp +++ b/roast/include/roast/web/css_attributes.hpp @@ -5,9 +5,6 @@ #ifndef __SFJP_ROAST__net__web__css_attributes_HPP__ #define __SFJP_ROAST__net__web__css_attributes_HPP__ -#include -#include - #include "roast/lexical.hpp" namespace roast @@ -16,561 +13,47 @@ namespace roast { namespace css { - /////////////////////////////////////////////////////////////////////////// - - class _base - { - protected: - ::std::string m_name; - ::std::string m_value; - _base(const char* name){ m_name = name; } - _base(const char* name, const char* value){ m_name = name; m_value = value; } - public: - ::std::string to_string() const { - ::std::string s = m_name; - s += ": "; - s += m_value; - s += ';'; - return s; - } - }; - - //typedef unsigned long color_t; - struct color_type - { - unsigned long value; - color_type(unsigned long v) : value(v) {} - color_type(unsigned char r, unsigned char g, unsigned char b) : - value(r<<16 | g<<8 | b) {} + namespace attributes + { +#define ROAST_CSS_DECL_ATTR(ATTRNAME) \ + namespace _attrname_str{ ROAST_LEXICAL_FIXSTR(_str_##ATTRNAME,#ATTRNAME); } \ + public: template struct ATTRNAME : _str_attr<_str_##ATTRNAME, T> {}; + + // padding: 4values (top, right, bottom, left) + template < + typename _Top=empty_type, + typename _Right=empty_type, + typename _Bottom=empty_type, + typename _Left=empty_type> + struct padding_ : declaration_<_attrname_str::padding, + seq<_Top, space, _Right, space, _Bottom, space, _Left> > + {}; - ::std::string to_string() const { - char work[8]; -#pragma warning(disable:4996) - sprintf(work, "#%06x", (0x00ffffff) & value ); -#pragma warning(default:4996) - return work; - } - }; - - /*class _color_attr - { - public: - _color_attr(const char* color_name) : _base("color", color_name) {} - _color_attr(const color_type& cl) : _base("color", cl.to_string().c_str()) {} - };*/ - - namespace unit - { -#pragma warning(disable:4996) - struct in{ - int value; - in(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%din", value); - return work; - } - }; - struct cm{ - int value; - cm(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dcm", value); - return work; - } - }; - struct mm{ - int value; - mm(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dmm", value); - return work; - } - }; - struct pt{ - int value; - pt(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dpt", value); - return work; - } - }; - struct pc{ - int value; - pc(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dpc", value); - return work; - } - }; - struct px{ - int value; - px(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dpx", value); - return work; - } - }; - struct ex{ - int value; - ex(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dex", value); - return work; - } - }; - struct em{ - int value; - em(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%dem", value); - return work; - } - }; - struct per{ - int value; - per(int v) : value(v) {} - ::std::string to_string() const - { - char work[16]; - sprintf(work, "%d%%", value); - return work; - } - }; -#pragma warning(default:4996) - } - - /////////////////////////////////////////////////////////////////////////// - - class color : public _base - { - public: - color(const char* color_name) : _base("color", color_name) {} - color(const color_type& cl) : _base("color", cl.to_string().c_str()) {} - color(unsigned long cl) : _base("color", color_type(cl).to_string().c_str()) {} - }; - - // background-color - class background_color : public _base - { - public: - background_color(const char* color_name) : _base("background-color", color_name) {} - background_color(const color_type& cl) : _base("background-color", cl.to_string().c_str()) {} - background_color(unsigned long cl) : _base("background-color", color_type(cl).to_string().c_str()) {} - }; - - // background-image - class background_image : public _base - { - private: - ::std::string _url(const char* url) const - { - ::std::string s("url("); - s += url; - s += ")"; - return s; - } - public: - background_image(const char* url) : _base("background-image", _url(url).c_str()) {} - }; - - // background-repeat - class background_repeat : public _base - { - public: - /*enum repeat - { - repeat, - repeat-x, - repeat-y, - no-repeat, - inherit - };*/ - static const class _repeat{} repeat; - static const class _repeat_x{} repeat_x; - static const class _repeat_y{} repeat_y; - static const class _no_repeat{} no_repeat; - static const class _inherit{} inherit; + // padding: 3values (top, LR, bottom) + template < + typename _Top, + typename _LR, + typename _Bottom> + struct padding_<_Top,_LR,_Bottom,empty_type> : declaration_<_attrname_str::padding, + seq<_Top, space, _LR, space, _Bottom> > + {}; - background_repeat(const _repeat &) : _base("background-repeat", "repeat") {} - background_repeat(const _repeat_x &) : _base("background-repeat", "repeat_x") {} - background_repeat(const _repeat_y &) : _base("background-repeat", "repeat_y") {} - background_repeat(const _no_repeat &) : _base("background-repeat", "no_repeat") {} - background_repeat(const _inherit &) : _base("background-repeat", "inherit") {} - }; - const background_repeat::_repeat background_repeat::repeat; - const background_repeat::_repeat_x background_repeat::repeat_x; - const background_repeat::_repeat_y background_repeat::repeat_y; - const background_repeat::_no_repeat background_repeat::no_repeat; - const background_repeat::_inherit background_repeat::inherit; - - // background-attachment - class background_attachment : public _base - { - public: - static const class _scroll{} scroll; - static const class _fixed{} fixed; - static const class _inherit{} inherit; + // padding: 2values (TB, LR) + template < + typename _TB, + typename _LR> + struct padding_<_TB,_LR,empty_type,empty_type> : declaration_<_attrname_str::padding, + seq > + {}; - background_attachment(const _scroll &) : _base("background-attachment", "scroll") {} - background_attachment(const _fixed &) : _base("background-attachment", "fixed") {} - background_attachment(const _inherit &) : _base("background-attachment", "inherit") {} - }; - const background_attachment::_scroll background_attachment::scroll; - const background_attachment::_fixed background_attachment::fixed; - const background_attachment::_inherit background_attachment::inherit; - - // background-position - class background_position : public _base - { - public: - static const class _left{} left; - static const class _center{} center; - static const class _right{} right; - static const class _top{} top; - static const class _bottom{} bottom; - private: - const char* _horizontal(const _left &){ return "left"; } - const char* _horizontal(const _center &){ return "center"; } - const char* _horizontal(const _right &){ return "right"; } - const char* _vertical(const _top &){ return "top"; } - const char* _vertical(const _center &){ return "center"; } - const char* _vertical(const _bottom &){ return "bottom"; } - - ::std::string _composite(const char* horizontal, const char* vertical){ - ::std::string s(horizontal); - s += ' '; - s += vertical; - return s; - } - public: - template - background_position(const T1 &t1, const T2 &t2) : _base("background-position", _composite(_horizontal(t1), _vertical(t2)).c_str() ) {} - }; - const background_position::_left background_position::left; - const background_position::_center background_position::center; - const background_position::_right background_position::right; - const background_position::_top background_position::top; - const background_position::_bottom background_position::bottom; - - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - // font-style - class font_style : public _base - { - public: - static const class _normal{} normal; - static const class _italic{} italic; - static const class _oblique{} oblique; - static const class _inherit{} inherit; - - font_style(const _normal &) : _base("font-style", "normal") {} - font_style(const _italic &) : _base("font-style", "fixed") {} - font_style(const _oblique &) : _base("font-style", "italic") {} - font_style(const _inherit &) : _base("font-style", "inherit") {} - }; - const font_style::_normal font_style::normal; - const font_style::_italic font_style::italic; - const font_style::_oblique font_style::oblique; - const font_style::_inherit font_style::inherit; - - // font-size - class font_size : public _base - { - public: - static const class _xx_small{} xx_small; - static const class _x_small{} x_small; - static const class _small{} small; - static const class _medium{} medium; - static const class _large{} large; - static const class _x_large{} x_large; - static const class _xx_large{} xx_large; - static const class _larger{} larger; - static const class _smaller{} smaller; - - font_size(const _xx_small &) : _base("font-size", "xx-small") {} - font_size(const _x_small &) : _base("font-size", "x-small") {} - font_size(const _small &) : _base("font-size", "small") {} - font_size(const _medium &) : _base("font-size", "medium") {} - font_size(const _large &) : _base("font-size", "large") {} - font_size(const _x_large &) : _base("font-size", "x-large") {} - font_size(const _xx_large &) : _base("font-size", "xx-large") {} - font_size(const _larger &) : _base("font-size", "larger") {} - font_size(const _smaller &) : _base("font-size", "smaller") {} - - font_size(const unit::in &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::cm &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::mm &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::pt &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::pc &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::px &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::ex &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::em &v) : _base("font-size", v.to_string().c_str()) {} - font_size(const unit::per &v) : _base("font-size", v.to_string().c_str()) {} - }; - const font_size::_xx_small font_size::xx_small; - const font_size::_x_small font_size::x_small; - const font_size::_small font_size::small; - const font_size::_medium font_size::medium; - const font_size::_large font_size::large; - const font_size::_x_large font_size::x_large; - const font_size::_xx_large font_size::xx_large; - const font_size::_larger font_size::larger; - const font_size::_smaller font_size::smaller; - - // font-family - class font_family : public _base - { - public: - static const char* get_attr_name(){ return "font-family"; } - - static const class _serif{} serif; - static const class _sans_serif{} sans_serif; - static const class _cursive{} cursive; - static const class _fantasy{} fantasy; - static const class _monospace{} monospace; - static const class _inherit{} inherit; - - font_family(const _serif &) : _base(get_attr_name(), "serif") {} - font_family(const _sans_serif &) : _base(get_attr_name(), "sans-serif") {} - font_family(const _cursive &) : _base(get_attr_name(), "cursive") {} - font_family(const _fantasy &) : _base(get_attr_name(), "fantasy") {} - font_family(const _monospace &) : _base(get_attr_name(), "monospace") {} - font_family(const _inherit &) : _base(get_attr_name(), "inherit") {} - }; - const font_family::_serif font_family::serif; - const font_family::_sans_serif font_family::sans_serif; - const font_family::_cursive font_family::cursive; - const font_family::_fantasy font_family::fantasy; - const font_family::_monospace font_family::monospace; - const font_family::_inherit font_family::inherit; - - // text-align - class text_align : public _base - { - public: - /*struct attr_name{ - const char* name; - attr_name() : name("text-align"){} - };*/ - static const char* get_attr_name(){ return "text-align"; } - - static const class _left{} left; - static const class _right{} right; - static const class _center{} center; - static const class _justify{} justify; - static const class _inherit{} inherit; - - text_align(const _left &) : _base(get_attr_name(), "left") {} - text_align(const _right &) : _base(get_attr_name(), "right") {} - text_align(const _center &) : _base(get_attr_name(), "center") {} - text_align(const _justify &) : _base(get_attr_name(), "justify") {} - text_align(const _inherit &) : _base(get_attr_name(), "inherit") {} - }; - const text_align::_left text_align::left; - const text_align::_right text_align::right; - const text_align::_center text_align::center; - const text_align::_justify text_align::justify; - const text_align::_inherit text_align::inherit; -/* -ƒ}[ƒWƒ“ -margin -margin-top -margin-right -margin-bottom -margin-left -ƒpƒfƒBƒ“ƒO -padding -padding-top -padding-right -padding-bottom -padding-left -ƒ{[ƒ_[ -border -border-top -border-right -border-bottom -border-left -border-width -border-top-width -border-right-width -border-bottom-width -border-left-width -border-style -border-top-style -border-right-style -border-bottom-style -border-left-style -border-color -border-top-color -border-right-color -border-bottom-color -border-left-color - -ƒAƒEƒgƒ‰ƒCƒ“ -outline -outline-width -outline-style -outline-color -ƒrƒWƒ…ƒAƒ‹ -display -position -top -left -bottom -right -float -clear -z-index -direction -unicode-bidi -width -height -min-width -min-height -max-width -max-height -vertical-align -overflow -overflow-x -overflow-y -clip -visibility -ƒRƒ“ƒeƒ“ƒgì¬ -content -quotes -counter-reset -counter-increment -marker-offset -ƒŠƒXƒg -list-style -list-style-type -list-style-position -list-style-image -ˆóü -page-break-before -page-break-after -page-break-inside -size -marks -page -orphans -widows - -”wŒi -background -background-color -background-image -background-repeat -background-attachment -background-position -ƒtƒHƒ“ƒg -font -font-style -font-variant -font-weight -font-size -line-height -font-family -font-stretch -font-size-adjust -ƒeƒLƒXƒg -text-indent -text-align -text-justify -text-decoration -text-underline-position -text-shadow -letter-spacing -word-spacing -text-transform -white-space -line-break -word-break -ruby-align -ruby-overhang -ruby-position -layout-grid -layout-grid-line -layout-grid-char -layout-grid-mode -layout-grid-type -text-autospace -text-kashida-space -writing-mode -ƒe[ƒuƒ‹ -caption-side -table-layout -border-collapse -border-spacing -empty-cells - -ƒ†[ƒUƒCƒ“ƒ^ƒtƒF[ƒX -cursor -ime-mode -behavior: url() -scrollbar-base-color -scrollbar-track-color -scrollbar-face-color -scrollbar-shadow-color -scrollbar-darkshadow-color -scrollbar-highlight-color -scrollbar-3dlight-color -scrollbar-arrow-color -‰¹ºŠÖ˜A -volume -speak -pause -pause-before -pause-after -cue -cue-after -cue-before -play-during -azimuth -elevation -speech-rate -voice-family -pitch -pitch-range -stress -richness -speak-punctuation -speak-numeral -speak-header -ƒtƒBƒ‹ƒ^ -filter: Alpha() -filter: Blur() -filter: Chroma() -filter: DropShadow() -filter: FlipH() -filter: FlipV() -filter: Glow() -filter: Gray() -filter: Invert() -filter: Light() -filter: Mask() -filter: Shadow() -filter: Wave() -filter: Xray() -*/ + // padding: 1values (LRTB) + template < + typename _LRTB> + struct padding_<_LRTB,empty_type,empty_type,empty_type> : declaration_<_attrname_str::padding, _LRTB> + {}; + } } } } -#endif//__SFJP_ROAST__net__web__css_attributes_HPP__ +#endif//__SFJP_ROAST__net__web__css_attributes_HPP__ \ No newline at end of file