YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ShellHelper.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2010 - 2013.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #include "Helper/ShellHelper.h"
29 #include <cstdio> // for std::sprintf;
30 
32 
33 #ifndef NDEBUG
35  : event_info(str), base_tick()
36 {
37  std::printf("Start tick of [%s] :\n", event_info.c_str());
38  base_tick = Timers::HighResolutionClock::now();
39 }
41 {
42  const double t((Timers::HighResolutionClock::now() - base_tick).count()
43  / 1e6);
44 
45  std::printf("Performed [%s] in: %f milliseconds.\n",
46  event_info.c_str(), t);
47 }
48 #endif
49 
50 
51 YSL_BEGIN_NAMESPACE(Drawing)
52 
53 string
54 to_string(const Size& s)
55 {
56  using YSLib::to_string;
57 
58  return "(" + to_string(s.Width) + ", " + to_string(s.Height) + ')';
59 }
60 string
61 to_string(const Rect& r)
62 {
63  using YSLib::to_string;
64 
65  return "(" + to_string(r.X) + ", " + to_string(r.Y) + ", "
66  + to_string(r.Width) + ", " + to_string(r.Height) + ')';
67 }
68 
69 YSL_END_NAMESPACE(Drawing)
70 
71 void
73 {
74  auto& app(FetchGlobalInstance());
75 
76  app.Queue.Remove(app.UIResponseLimit);
77 }
78 
79 
80 namespace
81 {
82 
84 inline void
85 snftime(char* buf, size_t /*n*/, const std::tm& tm,
86  const char* format = DefaultTimeFormat)
87 {
88  // FIXME: correct behavior for time with BC date(i.e. tm_year < -1900);
90  // tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
91  // FIXME: use std::snprintf;
92  std::sprintf(buf, format, tm.tm_year + 1900,
93  tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
94 }
95 
96 } // unnamed namespace;
97 
98 
99 const char*
100 TranslateTime(const std::tm& tm, const char* format)
101 {
102  static char str[80];
103 
104  // NOTE: 'std::strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", &tm)'
105  // is correct but it makes the object file too large.
106  snftime(str, 80, tm, format);
107  return str;
108 }
109 const char*
110 TranslateTime(const std::time_t& t, const char* format) ythrow(GeneralEvent)
111 {
112  auto p(std::localtime(&t));
113 
114  if(YB_UNLIKELY(!p))
115  throw GeneralEvent("Get broken-down time object failed"
116  " @ TranslateTime#2;");
117  return TranslateTime(*p, format);
118 }
119 
120 
121 shared_ptr<UI::TextList::ListType>
123 {
124  const auto& mFamilies(FetchDefaultFontCache().GetFamilyIndices());
125 
126  // TODO: Use g++ 4.8 or later.
127 // return make_shared<TextList::ListType>(mFamilies.cbegin()
128 // | ystdex::get_key, mFamilies.cend() | ystdex::get_key);
129  return share_raw(new UI::TextList::ListType(mFamilies.cbegin()
130  | ystdex::get_key, mFamilies.cend() | ystdex::get_key));
131 }
132 
133 
135  : last_tick(GetHighResolutionTicks()), now_tick(), refresh_count(1),
136  MinimalInterval(s)
137 {}
138 
139 u32
141 {
142  const u64 tmp_tick(GetHighResolutionTicks());
143 
144  if(YB_UNLIKELY(last_tick + MinimalInterval < tmp_tick))
145  {
147 
148  const u32 r(1000000000000ULL * refresh_count
149  / ((now_tick = tmp_tick) - last_tick));
150 
151  refresh_count = 1;
152  return r;
153  }
154  else
155  ++refresh_count;
156  return 0;
157 }
158 
160 
161 void
162 SwitchVisible(IWidget& wgt)
163 {
164  SetVisibleOf(wgt, !IsVisible(wgt));
165  Invalidate(wgt);
166 }
167 
169 
170 YSL_END
171