cursespp and musikbox are compiling! not running though.

This commit is contained in:
Casey Langen 2016-05-25 23:31:15 -07:00
parent e33f9928fb
commit d12eae819d
53 changed files with 290 additions and 225 deletions

View File

@ -48,10 +48,11 @@ set (musikbox_LINK_LIBS
include_directories ( include_directories (
"${musikbox_SOURCE_DIR}/src" "${musikbox_SOURCE_DIR}/src"
"${musikbox_SOURCE_DIR}/src/core" "${musikbox_SOURCE_DIR}/src/core"
"${musikbox_SOURCE_DIR}/src/musikbox"
"${musikbox_SOURCE_DIR}/src/3rdparty/include" "${musikbox_SOURCE_DIR}/src/3rdparty/include"
) )
add_subdirectory(src/3rdparty) add_subdirectory(src/3rdparty)
add_subdirectory(src/core) add_subdirectory(src/core)
#add_subdirectory(src/contrib) #add_subdirectory(src/contrib)
#add_subdirectory(src/musikbox) add_subdirectory(src/musikbox)

View File

@ -1,20 +1,84 @@
set (SQUARE_SRCS set (BOX_SRCS
stdafx.cpp ./Main.cpp
player.cpp ./stdafx.cpp
DummyAudioEventHandler.cpp ./app/layout/LibraryLayout.cpp
ConsoleUI.cpp ./app/layout/MainLayout.cpp
./app/query/CategoryListViewQuery.cpp
./app/query/SingleTrackQuery.cpp
./app/query/TrackListViewQuery.cpp
./app/service/PlaybackService.cpp
./app/util/GlobalHotkeys.cpp
./app/util/SystemInfo.cpp
./app/util/Text.cpp
./app/window/CategoryListView.cpp
./app/window/CommandWindow.cpp
./app/window/LogWindow.cpp
./app/window/OutputWindow.cpp
./app/window/ResourcesWindow.cpp
./app/window/TrackListView.cpp
./app/window/TransportWindow.cpp
./cursespp/Colors.cpp
./cursespp/LayoutBase.cpp
./cursespp/LayoutStack.cpp
./cursespp/ListWindow.cpp
./cursespp/Message.cpp
./cursespp/MessageQueue.cpp
./cursespp/MultiLineEntry.cpp
./cursespp/Screen.cpp
./cursespp/ScrollableWindow.cpp
./cursespp/ScrollAdapterBase.cpp
./cursespp/SimpleScrollAdapter.cpp
./cursespp/SingleLineEntry.cpp
./cursespp/Window.cpp
./cursespp/WindowLayout.cpp
) )
set (SQUARE_HEADERS set (BOX_HEADERS
config.h ./stdafx.h
ConsoleUI.h ./app/layout/LibraryLayout.h
DummyAudioEventHandler.h ./app/layout/MainLayout.h
memtrace.h ./app/query/CategoryListViewQuery.h
stdafx.h ./app/query/SingleTrackQuery.h
./app/query/TrackListViewQuery.h
./app/service/PlaybackService.h
./app/util/GlobalHotkeys.h
./app/util/SystemInfo.h
./app/util/Text.h
./app/window/CategoryListView.h
./app/window/CommandWindow.h
./app/window/LogWindow.h
./app/window/OutputWindow.h
./app/window/ResourcesWindow.h
./app/window/TrackListView.h
./app/window/TransportWindow.h
./cursespp/Colors.h
./cursespp/curses_config.h
./cursespp/IDisplayable.h
./cursespp/IInput.h
./cursespp/IKeyHandler.h
./cursespp/ILayout.h
./cursespp/ILayoutStack.h
./cursespp/IMessage.h
./cursespp/IMessageTarget.h
./cursespp/IOrderable.h
./cursespp/IScrollable.h
./cursespp/IScrollAdapter.h
./cursespp/IWindow.h
./cursespp/IWindowGroup.h
./cursespp/LayoutBase.h
./cursespp/LayoutStack.h
./cursespp/ListWindow.h
./cursespp/Message.h
./cursespp/MessageQueue.h
./cursespp/MultiLineEntry.h
./cursespp/Screen.h
./cursespp/ScrollableWindow.h
./cursespp/ScrollAdapterBase.h
./cursespp/SimpleScrollAdapter.h
./cursespp/SingleLineEntry.h
./cursespp/Window.h
./cursespp/WindowLayout.h
) )
SOURCE_GROUP ("Source Files" FILES ${SQUARE_SRCS}) add_executable(musikbox ${BOX_SRCS} ${BOX_HEADERS})
SOURCE_GROUP ("Header Files" FILES ${SQUARE_HEADERS}) target_link_libraries(musikbox ${musikbox_LINK_LIBS} curses panel musikcore)
add_executable(square ${SQUARE_SRCS} ${SQUARE_HEADERS})
target_link_libraries(square ${musikCube_LINK_LIBS} musik)

View File

@ -95,7 +95,7 @@ static void changeLayout(WindowState& current, ILayoutPtr newLayout) {
if (current.layout) { if (current.layout) {
current.layout->Hide(); current.layout->Hide();
current.layout = { 0 }; current.layout.reset();
} }
if (newLayout) { if (newLayout) {
@ -184,14 +184,17 @@ int main(int argc, char* argv[])
GlobalHotkeys globalHotkeys(playback, library); GlobalHotkeys globalHotkeys(playback, library);
ILayoutPtr libraryLayout(new LibraryLayout(playback, library)); ILayoutPtr libraryLayout((ILayout *) new LibraryLayout(playback, library));
ILayoutPtr consoleLayout(new MainLayout(tp, library)); ILayoutPtr consoleLayout((ILayout *) new MainLayout(tp, library));
int64 ch; int64 ch;
timeout(IDLE_TIMEOUT_MS); timeout(IDLE_TIMEOUT_MS);
bool quit = false; bool quit = false;
WindowState state = { 0 }; WindowState state;
state.input = NULL;
state.keyHandler = NULL;
changeLayout(state, libraryLayout); changeLayout(state, libraryLayout);
while (!quit) { while (!quit) {
@ -249,4 +252,3 @@ int main(int argc, char* argv[])
return 0; return 0;
} }

View File

@ -24,8 +24,8 @@ namespace musik {
virtual void Layout(); virtual void Layout();
virtual void Show(); virtual void Show();
virtual bool LibraryLayout::KeyPress(int64 ch);
virtual cursespp::IWindowPtr GetFocus(); virtual cursespp::IWindowPtr GetFocus();
virtual bool KeyPress(int64 ch);
private: private:
void InitializeWindows(); void InitializeWindows();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "MainLayout.h" #include "MainLayout.h"
#include <cursespp/Screen.h> #include <cursespp/Screen.h>

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "CategoryListViewQuery.h" #include "CategoryListViewQuery.h"
@ -17,7 +15,7 @@ using namespace musik::core::db;
using namespace musik::core::library::constants; using namespace musik::core::library::constants;
using namespace musik::box; using namespace musik::box;
#define reset(x) x.reset(new std::vector<std::shared_ptr<Result>>); #define reset(x) x.reset(new std::vector<std::shared_ptr<Result> >);
static const std::string ALBUM_QUERY = static const std::string ALBUM_QUERY =
"SELECT DISTINCT albums.id, albums.name " "SELECT DISTINCT albums.id, albums.name "
@ -41,9 +39,9 @@ static boost::mutex QUERY_MAP_MUTEX;
static std::map<std::string, std::string> FIELD_TO_QUERY_MAP; static std::map<std::string, std::string> FIELD_TO_QUERY_MAP;
static void initFieldToQueryMap() { static void initFieldToQueryMap() {
FIELD_TO_QUERY_MAP.emplace(Track::ALBUM_ID, ALBUM_QUERY); FIELD_TO_QUERY_MAP[Track::ALBUM_ID] = ALBUM_QUERY;
FIELD_TO_QUERY_MAP.emplace(Track::ARTIST_ID, ARTIST_QUERY); FIELD_TO_QUERY_MAP[Track::ARTIST_ID] = ARTIST_QUERY;
FIELD_TO_QUERY_MAP.emplace(Track::GENRE_ID, GENRE_QUERY); FIELD_TO_QUERY_MAP[Track::GENRE_ID] = GENRE_QUERY;
} }
CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) { CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) {

View File

@ -14,7 +14,7 @@ namespace musik {
}; };
typedef std::shared_ptr<std::vector< typedef std::shared_ptr<std::vector<
std::shared_ptr<Result>>> ResultList; std::shared_ptr<Result> > > ResultList;
CategoryListViewQuery(const std::string& trackField); CategoryListViewQuery(const std::string& trackField);
virtual ~CategoryListViewQuery(); virtual ~CategoryListViewQuery();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "SingleTrackQuery.h" #include "SingleTrackQuery.h"

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "TrackListViewQuery.h" #include "TrackListViewQuery.h"

View File

@ -10,7 +10,7 @@ namespace musik {
class TrackListViewQuery : public musik::core::query::QueryBase { class TrackListViewQuery : public musik::core::query::QueryBase {
public: public:
typedef std::shared_ptr< typedef std::shared_ptr<
std::vector<musik::core::TrackPtr>> Result; std::vector<musik::core::TrackPtr> > Result;
TrackListViewQuery( TrackListViewQuery(
musik::core::LibraryPtr library, musik::core::LibraryPtr library,

View File

@ -2,13 +2,14 @@
#include "SystemInfo.h" #include "SystemInfo.h"
using namespace musik::box;
#ifdef WIN32
#include "windows.h" #include "windows.h"
#include "psapi.h" #include "psapi.h"
#include "pdh.h" #include "pdh.h"
using namespace musik::box;
#ifdef WIN32
class WindowsSystemInfo : public SystemInfo { class WindowsSystemInfo : public SystemInfo {
public: public:
WindowsSystemInfo(); WindowsSystemInfo();

View File

@ -16,12 +16,13 @@ namespace musik {
size_t c = 0; size_t c = 0;
while (c < len && it != str.end()) { while (c < len && it != str.end()) {
try { try {
utf8::next(it++, end); utf8::next(it, end);
} }
catch (...) { catch (...) {
it++; /* invalid encoding, just treat as a single char */ /* invalid encoding, just treat as a single char */
} }
++it;
++c; ++c;
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include <cursespp/Colors.h> #include <cursespp/Colors.h>

View File

@ -20,7 +20,11 @@ using cursespp::ScrollAdapterBase;
namespace musik { namespace musik {
namespace box { namespace box {
class CategoryListView : public ListWindow, public sigslot::has_slots<> { class CategoryListView :
public ListWindow,
public std::enable_shared_from_this<CategoryListView>,
public sigslot::has_slots<>
{
public: public:
CategoryListView(LibraryPtr library, const std::string& fieldName); CategoryListView(LibraryPtr library, const std::string& fieldName);
virtual ~CategoryListView(); virtual ~CategoryListView();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include <cursespp/Screen.h> #include <cursespp/Screen.h>
@ -232,7 +230,7 @@ void CommandWindow::ListPlugins() const {
using musik::core::IPlugin; using musik::core::IPlugin;
using musik::core::PluginFactory; using musik::core::PluginFactory;
typedef std::vector<std::shared_ptr<IPlugin>> PluginList; typedef std::vector<std::shared_ptr<IPlugin> > PluginList;
typedef PluginFactory::NullDeleter<IPlugin> Deleter; typedef PluginFactory::NullDeleter<IPlugin> Deleter;
PluginList plugins = PluginFactory::Instance() PluginList plugins = PluginFactory::Instance()

View File

@ -12,6 +12,7 @@ namespace musik {
class CommandWindow : class CommandWindow :
public cursespp::Window, public cursespp::Window,
public cursespp::IInput, public cursespp::IInput,
public std::enable_shared_from_this<CommandWindow>,
public sigslot::has_slots<> public sigslot::has_slots<>
{ {
public: public:
@ -21,7 +22,7 @@ namespace musik {
musik::core::LibraryPtr library, musik::core::LibraryPtr library,
OutputWindow& output); OutputWindow& output);
~CommandWindow(); virtual ~CommandWindow();
virtual void WriteChar(int64 ch); virtual void WriteChar(int64 ch);
virtual void Focus(); virtual void Focus();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "LogWindow.h" #include "LogWindow.h"

View File

@ -11,10 +11,14 @@
namespace musik { namespace musik {
namespace box { namespace box {
class LogWindow : public cursespp::ScrollableWindow, public sigslot::has_slots<> { class LogWindow :
public cursespp::ScrollableWindow,
public std::enable_shared_from_this<LogWindow>,
public sigslot::has_slots<>
{
public: public:
LogWindow(cursespp::IWindow *parent = NULL); LogWindow(cursespp::IWindow *parent = NULL);
~LogWindow(); virtual ~LogWindow();
void Update(); void Update();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "OutputWindow.h" #include "OutputWindow.h"

View File

@ -7,16 +7,19 @@
namespace musik { namespace musik {
namespace box { namespace box {
class OutputWindow : public cursespp::ScrollableWindow { class OutputWindow :
public: public cursespp::ScrollableWindow,
OutputWindow(cursespp::IWindow *parent = NULL); public std::enable_shared_from_this<OutputWindow>
~OutputWindow(); {
public:
OutputWindow(cursespp::IWindow *parent = NULL);
virtual ~OutputWindow();
void WriteLine(const std::string& line, int64 attrs = -1); void WriteLine(const std::string& line, int64 attrs = -1);
virtual cursespp::IScrollAdapter& GetScrollAdapter(); virtual cursespp::IScrollAdapter& GetScrollAdapter();
private: private:
cursespp::SimpleScrollAdapter* adapter; cursespp::SimpleScrollAdapter* adapter;
}; };
} }
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "ResourcesWindow.h" #include "ResourcesWindow.h"

View File

@ -7,7 +7,10 @@
namespace musik { namespace musik {
namespace box { namespace box {
class ResourcesWindow : public cursespp::Window { class ResourcesWindow :
public cursespp::Window,
public std::enable_shared_from_this<ResourcesWindow>
{
public: public:
ResourcesWindow(cursespp::IWindow *parent = NULL); ResourcesWindow(cursespp::IWindow *parent = NULL);
virtual ~ResourcesWindow(); virtual ~ResourcesWindow();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include <cursespp/Colors.h> #include <cursespp/Colors.h>

View File

@ -13,13 +13,17 @@
namespace musik { namespace musik {
namespace box { namespace box {
class TrackListView : public cursespp::ListWindow, public sigslot::has_slots<> { class TrackListView :
public cursespp::ListWindow,
public std::enable_shared_from_this<TrackListView>,
public sigslot::has_slots<>
{
public: public:
TrackListView( TrackListView(
PlaybackService& playback, PlaybackService& playback,
musik::core::LibraryPtr library); musik::core::LibraryPtr library);
~TrackListView(); virtual ~TrackListView();
virtual void ProcessMessage(cursespp::IMessage &message); virtual void ProcessMessage(cursespp::IMessage &message);
virtual bool KeyPress(int64 ch); virtual bool KeyPress(int64 ch);
@ -44,7 +48,7 @@ namespace musik {
private: private:
std::shared_ptr<TrackListViewQuery> query; std::shared_ptr<TrackListViewQuery> query;
std::shared_ptr<std::vector<TrackPtr>> metadata; std::shared_ptr<std::vector<TrackPtr> > metadata;
Adapter* adapter; Adapter* adapter;
PlaybackService& playback; PlaybackService& playback;
musik::core::LibraryPtr library; musik::core::LibraryPtr library;

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "TransportWindow.h" #include "TransportWindow.h"
@ -18,6 +16,8 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
#include <algorithm>
using namespace musik::core; using namespace musik::core;
using namespace musik::core::audio; using namespace musik::core::audio;
using namespace musik::core::library; using namespace musik::core::library;
@ -146,7 +146,7 @@ void TransportWindow::Update() {
wprintw(c, "\n"); wprintw(c, "\n");
int volumePercent = (size_t) round(this->transport->Volume() * 100.0f) - 1; int volumePercent = (size_t) round(this->transport->Volume() * 100.0f) - 1;
int thumbOffset = min(9, (volumePercent * 10) / 100); int thumbOffset = std::min(9, (volumePercent * 10) / 100);
std::string volume = "vol "; std::string volume = "vol ";
@ -190,7 +190,7 @@ void TransportWindow::Update() {
if (secondsTotal) { if (secondsTotal) {
size_t progress = (secondsCurrent * 100) / secondsTotal; size_t progress = (secondsCurrent * 100) / secondsTotal;
thumbOffset = min(timerWidth - 1, (progress * timerWidth) / 100); thumbOffset = std::min(timerWidth - 1, (progress * timerWidth) / 100);
} }
std::string timerTrack = ""; std::string timerTrack = "";

View File

@ -10,7 +10,11 @@
namespace musik { namespace musik {
namespace box { namespace box {
class TransportWindow : public cursespp::Window, public sigslot::has_slots<> { class TransportWindow :
public cursespp::Window,
public std::enable_shared_from_this<TransportWindow>,
public sigslot::has_slots<>
{
public: public:
TransportWindow( TransportWindow(
musik::core::LibraryPtr library, musik::core::LibraryPtr library,

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "Colors.h" #include "Colors.h"

View File

@ -3,9 +3,8 @@
namespace cursespp { namespace cursespp {
class IDisplayable { class IDisplayable {
public: public:
virtual ~IDisplayable() = 0 { } virtual ~IDisplayable() { }
virtual void Show() = 0; virtual void Show() = 0;
virtual void Hide() = 0; virtual void Hide() = 0;
}; };
} }

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IInput { class IInput {
public: public:
virtual ~IInput() = 0 { } virtual ~IInput() { }
virtual void WriteChar(int64 ch) = 0; virtual void WriteChar(int64 ch) = 0;
}; };
} }

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IKeyHandler { class IKeyHandler {
public: public:
virtual ~IKeyHandler() = 0 { } virtual ~IKeyHandler() { }
virtual bool KeyPress(int64 ch) = 0; virtual bool KeyPress(int64 ch) = 0;
}; };
} }

View File

@ -10,7 +10,7 @@ namespace cursespp {
class ILayout : public IWindowGroup, public IKeyHandler, public IOrderable, public IDisplayable { class ILayout : public IWindowGroup, public IKeyHandler, public IOrderable, public IDisplayable {
public: public:
virtual ~ILayout() = 0 { } virtual ~ILayout() { }
virtual IWindowPtr FocusNext() = 0; virtual IWindowPtr FocusNext() = 0;
virtual IWindowPtr FocusPrev() = 0; virtual IWindowPtr FocusPrev() = 0;
virtual IWindowPtr GetFocus() = 0; virtual IWindowPtr GetFocus() = 0;

View File

@ -6,7 +6,7 @@
namespace cursespp { namespace cursespp {
class ILayoutStack { class ILayoutStack {
public: public:
virtual ~ILayoutStack() = 0 { } virtual ~ILayoutStack() { }
virtual bool Push(ILayoutPtr layout) = 0; virtual bool Push(ILayoutPtr layout) = 0;
virtual bool Pop(ILayoutPtr layout) = 0; virtual bool Pop(ILayoutPtr layout) = 0;
virtual bool BringToTop(ILayoutPtr layout) = 0; virtual bool BringToTop(ILayoutPtr layout) = 0;

View File

@ -9,7 +9,7 @@ namespace cursespp {
class IMessage { class IMessage {
public: public:
virtual ~IMessage() = 0 { } virtual ~IMessage() { }
virtual IMessageTarget* Target() = 0; virtual IMessageTarget* Target() = 0;
virtual int Type() = 0; virtual int Type() = 0;
virtual int64 UserData1() = 0; virtual int64 UserData1() = 0;

View File

@ -5,6 +5,7 @@
namespace cursespp { namespace cursespp {
class IMessageTarget { class IMessageTarget {
public: public:
virtual ~IMessageTarget() { }
virtual bool IsAcceptingMessages() = 0; virtual bool IsAcceptingMessages() = 0;
virtual void ProcessMessage(IMessage &message) = 0; virtual void ProcessMessage(IMessage &message) = 0;
}; };

View File

@ -3,7 +3,7 @@
namespace cursespp { namespace cursespp {
class IOrderable { class IOrderable {
public: public:
virtual ~IOrderable() = 0 { } virtual ~IOrderable() { }
virtual void BringToTop() = 0; virtual void BringToTop() = 0;
virtual void SendToBottom() = 0; virtual void SendToBottom() = 0;
}; };

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IScrollAdapter { class IScrollAdapter {
public: public:
virtual ~IScrollAdapter() = 0 { } virtual ~IScrollAdapter() { }
struct ScrollPosition { struct ScrollPosition {
ScrollPosition() { ScrollPosition() {
@ -25,7 +25,7 @@ namespace cursespp {
class IEntry { class IEntry {
public: public:
virtual ~IEntry() = 0 { } virtual ~IEntry() { }
virtual size_t GetLineCount() = 0; virtual size_t GetLineCount() = 0;
virtual std::string GetLine(size_t line) = 0; virtual std::string GetLine(size_t line) = 0;
virtual std::string GetValue() = 0; virtual std::string GetValue() = 0;
@ -42,4 +42,3 @@ namespace cursespp {
virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) = 0; virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) = 0;
}; };
} }

View File

@ -3,7 +3,7 @@
namespace cursespp { namespace cursespp {
class IScrollable { class IScrollable {
public: public:
virtual ~IScrollable() = 0 { } virtual ~IScrollable() { }
virtual void ScrollToTop() = 0; virtual void ScrollToTop() = 0;
virtual void ScrollToBottom() = 0; virtual void ScrollToBottom() = 0;
virtual void ScrollUp(int delta = 1) = 0; virtual void ScrollUp(int delta = 1) = 0;

View File

@ -10,7 +10,7 @@ namespace cursespp {
class IWindow : public IOrderable, public IDisplayable, public IMessageTarget { class IWindow : public IOrderable, public IDisplayable, public IMessageTarget {
public: public:
virtual ~IWindow() = 0 { } virtual ~IWindow() { }
virtual void Repaint() = 0; virtual void Repaint() = 0;
virtual void SetParent(IWindow* parent) = 0; virtual void SetParent(IWindow* parent) = 0;
virtual void Show() = 0; virtual void Show() = 0;

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IWindowGroup { class IWindowGroup {
public: public:
virtual ~IWindowGroup() = 0 { } virtual ~IWindowGroup() { }
virtual bool AddWindow(IWindowPtr window) = 0; virtual bool AddWindow(IWindowPtr window) = 0;
virtual bool RemoveWindow(IWindowPtr window) = 0; virtual bool RemoveWindow(IWindowPtr window) = 0;
virtual size_t GetWindowCount() = 0; virtual size_t GetWindowCount() = 0;

View File

@ -7,7 +7,7 @@ using namespace cursespp;
template <typename T> static int find(std::vector<T>& haystack, T& needle) { template <typename T> static int find(std::vector<T>& haystack, T& needle) {
int i = 0; int i = 0;
std::vector<T>::iterator it = haystack.begin(); typename std::vector<T>::iterator it = haystack.begin();
for (; it != haystack.end(); it++, i++) { for (; it != haystack.end(); it++, i++) {
if ((*it) == needle) { if ((*it) == needle) {
return i; return i;

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "LayoutStack.h" #include "LayoutStack.h"
@ -40,19 +38,19 @@ static inline bool erase(std::deque<ILayoutPtr>& group, ILayoutPtr ptr) {
} }
bool LayoutStack::AddWindow(IWindowPtr window) { bool LayoutStack::AddWindow(IWindowPtr window) {
throw std::exception("AddWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()");
} }
bool LayoutStack::RemoveWindow(IWindowPtr window) { bool LayoutStack::RemoveWindow(IWindowPtr window) {
throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()");
} }
size_t LayoutStack::GetWindowCount() { size_t LayoutStack::GetWindowCount() {
throw std::exception("GetWindowCount() not supported in LayoutStack."); throw std::runtime_error("GetWindowCount() not supported in LayoutStack.");
} }
IWindowPtr LayoutStack::GetWindowAt(size_t position) { IWindowPtr LayoutStack::GetWindowAt(size_t position) {
throw std::exception("GetWindowAt() not supported in LayoutStack."); throw std::runtime_error("GetWindowAt() not supported in LayoutStack.");
} }
ILayoutStack* LayoutStack::GetLayoutStack() { ILayoutStack* LayoutStack::GetLayoutStack() {

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include <stdafx.h>
#include <algorithm>
#include "ListWindow.h" #include "ListWindow.h"
using namespace cursespp; using namespace cursespp;
@ -24,7 +25,7 @@ void ListWindow::ScrollToTop() {
void ListWindow::ScrollToBottom() { void ListWindow::ScrollToBottom() {
IScrollAdapter& adapter = this->GetScrollAdapter(); IScrollAdapter& adapter = this->GetScrollAdapter();
this->SetSelectedIndex(max(0, adapter.GetEntryCount() - 1)); this->SetSelectedIndex(std::max(0UL, adapter.GetEntryCount() - 1));
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition); adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
this->Repaint(); this->Repaint();
} }
@ -46,13 +47,13 @@ void ListWindow::ScrollUp(int delta) {
int minIndex = 0; int minIndex = 0;
int newIndex = this->selectedIndex - delta; int newIndex = this->selectedIndex - delta;
newIndex = max(newIndex, minIndex); newIndex = std::max(newIndex, minIndex);
if (newIndex < (int) first + 1) { if (newIndex < (int) first + 1) {
drawIndex = newIndex - 1; drawIndex = newIndex - 1;
} }
drawIndex = max(0, drawIndex); drawIndex = std::max(0, drawIndex);
this->SetSelectedIndex(newIndex); this->SetSelectedIndex(newIndex);
@ -75,7 +76,7 @@ void ListWindow::ScrollDown(int delta) {
size_t maxIndex = adapter.GetEntryCount() - 1; size_t maxIndex = adapter.GetEntryCount() - 1;
size_t newIndex = this->selectedIndex + delta; size_t newIndex = this->selectedIndex + delta;
newIndex = min(newIndex, maxIndex); newIndex = std::min(newIndex, maxIndex);
if (newIndex >= last - 1) { if (newIndex >= last - 1) {
drawIndex = drawIndex + delta; drawIndex = drawIndex + delta;
@ -112,7 +113,7 @@ void ListWindow::PageDown() {
ScrollPos spos = this->GetScrollPosition(); ScrollPos spos = this->GetScrollPosition();
size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1; size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1;
this->SetSelectedIndex(min(adapter.GetEntryCount() - 1, lastVisible + 1)); this->SetSelectedIndex(std::min(adapter.GetEntryCount() - 1, lastVisible + 1));
adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition); adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition);
this->Repaint(); this->Repaint();

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include <stdafx.h>
#include <algorithm>
#include "MessageQueue.h" #include "MessageQueue.h"
using namespace boost::chrono; using namespace boost::chrono;
@ -81,7 +82,7 @@ void MessageQueue::Remove(IMessageTarget *target, int type) {
void MessageQueue::Post(IMessagePtr message, int64 delayMs) { void MessageQueue::Post(IMessagePtr message, int64 delayMs) {
boost::recursive_mutex::scoped_lock lock(this->queueMutex); boost::recursive_mutex::scoped_lock lock(this->queueMutex);
delayMs = max(0, delayMs); delayMs = std::max(0LL, delayMs);
milliseconds now = duration_cast<milliseconds>( milliseconds now = duration_cast<milliseconds>(
system_clock::now().time_since_epoch()); system_clock::now().time_since_epoch());

View File

@ -1,6 +1,8 @@
#include <stdafx.h> #include <stdafx.h>
#include "MultiLineEntry.h" #include <math.h>
#include <algorithm>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "MultiLineEntry.h"
using namespace cursespp; using namespace cursespp;
@ -12,7 +14,7 @@ MultiLineEntry::MultiLineEntry(const std::string& value, int64 attrs) {
} }
size_t MultiLineEntry::GetLineCount() { size_t MultiLineEntry::GetLineCount() {
return max(1, this->lines.size()); return std::max(1UL, this->lines.size());
} }
std::string MultiLineEntry::GetLine(size_t n) { std::string MultiLineEntry::GetLine(size_t n) {

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "Screen.h" #include "Screen.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include <algorithm>
#include "ScrollableWindow.h" #include "ScrollableWindow.h"
#include "Screen.h" #include "Screen.h"
#include "Colors.h" #include "Colors.h"
@ -122,7 +122,7 @@ size_t ScrollableWindow::GetPreviousPageEntryIndex() {
remaining -= count; remaining -= count;
} }
return max(0, i); return std::max(0, i);
} }
void ScrollableWindow::PageUp() { void ScrollableWindow::PageUp() {

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "Window.h" #include "Window.h"
#include "IWindowGroup.h" #include "IWindowGroup.h"

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "WindowLayout.h" #include "WindowLayout.h"
#include "LayoutStack.h" #include "LayoutStack.h"
@ -15,19 +13,19 @@ WindowLayout::~WindowLayout() {
} }
bool WindowLayout::AddWindow(IWindowPtr window) { bool WindowLayout::AddWindow(IWindowPtr window) {
throw std::exception("AddWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()");
} }
bool WindowLayout::RemoveWindow(IWindowPtr window) { bool WindowLayout::RemoveWindow(IWindowPtr window) {
throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()");
} }
size_t WindowLayout::GetWindowCount() { size_t WindowLayout::GetWindowCount() {
throw std::exception("GetWindowCount() not supported in LayoutStack."); throw std::runtime_error("GetWindowCount() not supported in LayoutStack.");
} }
IWindowPtr WindowLayout::GetWindowAt(size_t position) { IWindowPtr WindowLayout::GetWindowAt(size_t position) {
throw std::exception("GetWindowAt() not supported in LayoutStack."); throw std::runtime_error("GetWindowAt() not supported in LayoutStack.");
} }
void WindowLayout::Show() { void WindowLayout::Show() {