NAP
Public Member Functions | Public Attributes | List of all members
CalendarInstance Class Referencefinal

#include <calendar.h>

Public Member Functions

 CalendarInstance (nap::Core &core)
 
 CalendarInstance (const CalendarInstance &rhs)=delete
 
CalendarInstanceoperator= (const CalendarInstance &rhs)=delete
 
bool init (const std::string &name, bool allowFailure, CalendarItemList defaultItems, utility::ErrorState &error)
 
const std::string & getName () const
 
std::string getPath () const
 
const OwnedCalendarItemListgetItems () const
 
template<typename T >
void getItems (std::vector< T * > &outItems) const
 
void addItem (std::unique_ptr< CalendarItem > item)
 
template<typename T , typename... Args>
T * addItem (Args &&... args)
 
bool removeItem (const std::string &id)
 
CalendarItemfindByID (const std::string &id)
 
template<typename T >
T * findByID (const std::string &id)
 
CalendarItemfindByTitle (const std::string &title)
 
template<typename T >
T * findByTitle (const std::string &title)
 
bool save (utility::ErrorState &error)
 

Public Attributes

Signal< const CalendarItem & > itemRemoved
 Called when an item is about to be removed. More...
 
Signal< const CalendarItem & > itemAdded
 Called when an item is added. More...
 
OwnedCalendarItemList mItems
 List of unique calendar items. More...
 
std::string mName
 Calendar name. More...
 
std::string mPath
 Path to calendar file on disk. More...
 
nap::CoremCore
 NAP core. More...
 

Description

Actual runtime version of a simple calendar, created by a nap::ICalendar resource on initialization. Allows for inspection, creation, loading and saving of calendar items. This model is: NOT THREAD SAFE. Don't edit, remove or add items on a different thread!

Collaboration diagram for CalendarInstance:
[legend]

Constructor & Destructor Documentation

◆ CalendarInstance() [1/2]

◆ CalendarInstance() [2/2]

CalendarInstance ( const CalendarInstance rhs)
delete

Member Function Documentation

◆ addItem() [1/2]

T * addItem ( Args &&...  args)

Creates, initializes and adds a new item of the given type T to the calendar. Item must be of type: nap::CalendarItem and is given a unique id. The item is managed by the calendar.

UniqueCalendarItem* new_item = calendar.addItem<UniqueCalendarItem>
(
CalendarItem::Point({ 12, 0 }, { 1, 0 }),
"Birthday Celebrations",
Date(2021, EMonth::January, 29)
);
Parameters
argsspecific calendar item construction arguments
Returns
the new calendar item, nullptr if the item can't be created or initialized

◆ addItem() [2/2]

void addItem ( std::unique_ptr< CalendarItem item)

Adds an item to this calendar. This call does not initialize the item for you. The new item must be initialized and valid. Ownership is transferred.

Parameters
itemthe item to add

◆ findByID() [1/2]

CalendarItem* findByID ( const std::string &  id)

Find a calendar item by ID

Parameters
iditem unique ID
Returns
calendar item if found, nullptr otherwise

◆ findByID() [2/2]

T* findByID ( const std::string &  id)

Find a calendar item of type T by ID

UniqueCalendarItem* item = calendar.findItem<UniqueCalendarItem>("9032091")
Parameters
iditem unique ID
Returns
calendar item of type T if found, nullptr otherwise

◆ findByTitle() [1/2]

CalendarItem* findByTitle ( const std::string &  title)

Find a calendar item by title, case sensitive.

Parameters
titleitem title
Returns
calendar item if found, nullptr otherwise

◆ findByTitle() [2/2]

T* findByTitle ( const std::string &  title)

Find a calendar item of type T by title, case sensitive.

UniqueCalendarItem* item = calendar.findItem<UniqueCalendarItem>("birthday")
Parameters
titleitem title
Returns
calendar item of type T if found, nullptr otherwise

◆ getItems() [1/2]

const OwnedCalendarItemList& getItems ( ) const
Returns
all calendar items

◆ getItems() [2/2]

void getItems ( std::vector< T * > &  outItems) const

Returns all calendar items of type T. List is not cleared.

std::vector<WeeklyCalendarItem*> items;
mCalendar->getInstance().getItems(items);
Parameters
outItemsall calendar items of type T

◆ getName()

const std::string& getName ( ) const
Returns
name of calendar

◆ getPath()

std::string getPath ( ) const
Returns
absolute path to calendar file on disk

◆ init()

bool init ( const std::string &  name,
bool  allowFailure,
CalendarItemList  defaultItems,
utility::ErrorState error 
)

Initialize the calendar using the given name and items. If a calendar with the given name is present on disk, it is loaded instead. Call saveCalendar() to write the calendar to disk.

Parameters
namename of the calendar to create
allowFailureif default items are created when loading from disk fails (file might be corrupt for example).
defaultItemsdefault set of items to create calendar with
errorcontains the error if initialization fails

◆ operator=()

CalendarInstance& operator= ( const CalendarInstance rhs)
delete

◆ removeItem()

bool removeItem ( const std::string &  id)

Remove an item based on id. Note that handles are invalid after this call.

Parameters
idthe unique id of the item to remove
Returns
if the item was removed

◆ save()

bool save ( utility::ErrorState error)

Writes the calendar to disk.

Parameters
errorcontains the error if writing fails

Member Data Documentation

◆ itemAdded

Signal<const CalendarItem&> itemAdded

Called when an item is added.

◆ itemRemoved

Signal<const CalendarItem&> itemRemoved

Called when an item is about to be removed.

◆ mCore

nap::Core& mCore

NAP core.

◆ mItems

List of unique calendar items.

◆ mName

std::string mName

Calendar name.

◆ mPath

std::string mPath

Path to calendar file on disk.

nap::EMonth::January
@ January
January.