some refactoring in miscspace(.h|.cpp)
space() renamed to space_value() and takes a third parameter: escape (bool) space_noescape() removed space_tab() renamed to space_list_tab() space_tab_value() renamed to space_list_tab_value() space_tab_has_next() renamed to space_list_tab_has_next() git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1035 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
7ed41a03ae
commit
42144bb31c
|
@ -131,7 +131,7 @@ void gallery_tab_meta(Info & i)
|
|||
if( gallery_index < gallery_info.item_sort_tab.size() )
|
||||
{
|
||||
Item & item = *gallery_info.item_sort_tab[gallery_index];
|
||||
space(i, item.meta);
|
||||
space_value(i, item.meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ void gallery_tab_meta_tab(Info & i)
|
|||
if( gallery_index < gallery_info.item_sort_tab.size() )
|
||||
{
|
||||
Item & item = *gallery_info.item_sort_tab[gallery_index];
|
||||
spaces_tab(i, item.meta);
|
||||
space_list_tab(i, item.meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ void gallery_tab_meta_tab_value(Info & i)
|
|||
if( gallery_index < gallery_info.item_sort_tab.size() )
|
||||
{
|
||||
Item & item = *gallery_info.item_sort_tab[gallery_index];
|
||||
spaces_tab_value(i, item.meta);
|
||||
space_list_tab_value(i, item.meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ void gallery_tab_meta_tab_has_next(Info & i)
|
|||
if( gallery_index < gallery_info.item_sort_tab.size() )
|
||||
{
|
||||
Item & item = *gallery_info.item_sort_tab[gallery_index];
|
||||
spaces_tab_has_next(i, item.meta);
|
||||
space_list_tab_has_next(i, item.meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -382,7 +382,7 @@ void menu_dir_tab_meta(Info & i)
|
|||
StackItem * sitem = reinterpret_cast<StackItem*>(stack->fun_data);
|
||||
|
||||
if( stack->iter < sitem->citem->menu_items.size() )
|
||||
space(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
space_value(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ void menu_dir_tab_meta_tab(Info & i)
|
|||
StackItem * sitem = reinterpret_cast<StackItem*>(stack->fun_data);
|
||||
|
||||
if( stack->iter < sitem->citem->menu_items.size() )
|
||||
spaces_tab(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
space_list_tab(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ void menu_dir_tab_meta_tab_value(Info & i)
|
|||
StackItem * sitem = reinterpret_cast<StackItem*>(stack->fun_data);
|
||||
|
||||
if( stack->iter < sitem->citem->menu_items.size() )
|
||||
spaces_tab_value(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
space_list_tab_value(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,7 +417,7 @@ void menu_dir_tab_meta_tab_has_next(Info & i)
|
|||
StackItem * sitem = reinterpret_cast<StackItem*>(stack->fun_data);
|
||||
|
||||
if( stack->iter < sitem->citem->menu_items.size() )
|
||||
spaces_tab_has_next(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
space_list_tab_has_next(i, sitem->citem->menu_items[stack->iter].meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ void ticket_is_creating_new(Info & i)
|
|||
void ticket_meta_value(Info & i)
|
||||
{
|
||||
if( ticket_info.item )
|
||||
space(i, ticket_info.item->meta);
|
||||
space_value(i, ticket_info.item->meta);
|
||||
}
|
||||
|
||||
void ticket_is_closed(Info & i)
|
||||
|
@ -587,7 +587,7 @@ void tickets_tab_meta_value(Info & i)
|
|||
tickets_tab_check_reqid();
|
||||
|
||||
if( tickets_value.is_item )
|
||||
space(i, tickets_value.item->meta);
|
||||
space_value(i, tickets_value.item->meta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -870,7 +870,7 @@ void tickets_tab_conf_tab_file_tab_meta(Info & i)
|
|||
PT::Space & mt = *value.value_meta;
|
||||
|
||||
if( tickets_file_index < mt.spaces.size() )
|
||||
space(i, *mt.spaces[tickets_file_index]);
|
||||
space_value(i, *mt.spaces[tickets_file_index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -997,7 +997,7 @@ void ticket_tab_value_meta(Info & i)
|
|||
ticket_tab_check_reqid();
|
||||
|
||||
if( value.is_value && !value.is_in_ticket_par )
|
||||
space(i, *value.value_meta);
|
||||
space_value(i, *value.value_meta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1089,7 +1089,7 @@ void ticket_tab_select_tab_meta(Info & i)
|
|||
PT::Space & sp = *value.config_par;
|
||||
|
||||
if( select_index < sp.spaces.size() )
|
||||
space(i, *sp.spaces[select_index]);
|
||||
space_value(i, *sp.spaces[select_index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1168,7 +1168,7 @@ void ticket_tab_file_tab_meta(Info & i)
|
|||
PT::Space & mt = *value.value_meta;
|
||||
|
||||
if( ticket_file_index < mt.spaces.size() )
|
||||
space(i, *mt.spaces[ticket_file_index]);
|
||||
space_value(i, *mt.spaces[ticket_file_index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -470,26 +470,26 @@ void dir_last_meta_str(Info & i)
|
|||
|
||||
void dir_last_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->dir_tab.back()->meta);
|
||||
space_value(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->dir_tab.back()->meta);
|
||||
space_list_tab(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->dir_tab.back()->meta);
|
||||
space_list_tab_value(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dir_last_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->dir_tab.back()->meta);
|
||||
space_list_tab_has_next(i, cur->request->dir_tab.back()->meta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -503,25 +503,25 @@ void dir_last_admin_meta_str(Info & i)
|
|||
|
||||
void dir_last_admin_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->dir_tab.back()->ameta);
|
||||
space_value(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->dir_tab.back()->ameta);
|
||||
space_list_tab(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->dir_tab.back()->ameta);
|
||||
space_list_tab_value(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
void dir_last_admin_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->dir_tab.back()->ameta);
|
||||
space_list_tab_has_next(i, cur->request->dir_tab.back()->ameta);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ void env(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
space(i, puser->env);
|
||||
space_value(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ void env_tab(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab(i, puser->env);
|
||||
space_list_tab(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,7 +79,7 @@ void env_tab_value(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_value(i, puser->env);
|
||||
space_list_tab_value(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@ void env_tab_has_next(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_has_next(i, puser->env);
|
||||
space_list_tab_has_next(i, puser->env);
|
||||
}
|
||||
|
||||
|
||||
|
@ -114,7 +114,7 @@ void env_admin(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
space(i, puser->aenv);
|
||||
space_value(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,7 +123,7 @@ void env_admin_tab(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab(i, puser->aenv);
|
||||
space_list_tab(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,7 +132,7 @@ void env_admin_tab_value(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_value(i, puser->aenv);
|
||||
space_list_tab_value(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,7 +142,7 @@ void env_admin_tab_has_next(Info & i)
|
|||
User * puser = cur->session->puser;
|
||||
|
||||
if( puser )
|
||||
spaces_tab_has_next(i, puser->aenv);
|
||||
space_list_tab_has_next(i, puser->aenv);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -422,7 +422,7 @@ void item_meta_str(Info & i)
|
|||
|
||||
void item_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->last_item->meta); // !! a new interface (last_item instead of item)
|
||||
space_value(i, cur->request->last_item->meta); // !! a new interface (last_item instead of item)
|
||||
}
|
||||
|
||||
|
||||
|
@ -430,20 +430,20 @@ void item_meta(Info & i)
|
|||
|
||||
void item_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->last_item->meta);
|
||||
space_list_tab(i, cur->request->last_item->meta);
|
||||
}
|
||||
|
||||
|
||||
void item_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->last_item->meta);
|
||||
space_list_tab_value(i, cur->request->last_item->meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void item_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->last_item->meta);
|
||||
space_list_tab_has_next(i, cur->request->last_item->meta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -457,25 +457,25 @@ void item_admin_meta_str(Info & i)
|
|||
|
||||
void item_admin_meta(Info & i)
|
||||
{
|
||||
space(i, cur->request->last_item->ameta);
|
||||
space_value(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta_tab(Info & i)
|
||||
{
|
||||
spaces_tab(i, cur->request->last_item->ameta);
|
||||
space_list_tab(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta_tab_value(Info & i)
|
||||
{
|
||||
spaces_tab_value(i, cur->request->last_item->ameta);
|
||||
space_list_tab_value(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
void item_admin_meta_tab_has_next(Info & i)
|
||||
{
|
||||
spaces_tab_has_next(i, cur->request->last_item->ameta);
|
||||
space_list_tab_has_next(i, cur->request->last_item->ameta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -847,21 +847,21 @@ void item_tab_meta_str(Info & i)
|
|||
void item_tab_meta(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
space(i, cur->request->item_tab[item_index].meta);
|
||||
space_value(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_meta_tab(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
spaces_tab(i, cur->request->item_tab[item_index].meta);
|
||||
space_list_tab(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
void item_tab_meta_tab_value(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
spaces_tab_value(i, cur->request->item_tab[item_index].meta);
|
||||
space_list_tab_value(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
|
@ -869,7 +869,7 @@ void item_tab_meta_tab_value(Info & i)
|
|||
void item_tab_meta_tab_has_next(Info & i)
|
||||
{
|
||||
if( item_index < cur->request->item_tab.size() )
|
||||
spaces_tab_has_next(i, cur->request->item_tab[item_index].meta);
|
||||
space_list_tab_has_next(i, cur->request->item_tab[item_index].meta);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* Copyright (c) 2012-2016, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -37,11 +37,12 @@
|
|||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
bool are_spaces_the_same(const std::vector<Ezc::Var> & params, const std::vector<std::wstring> & spaces)
|
||||
{
|
||||
// last value from params is the parameter name (not a space)
|
||||
|
@ -95,7 +96,12 @@ PT::Space * find_space(const std::vector<Ezc::Var> & params, PT::Space & space,
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* IMPROVE ME
|
||||
* add a private namespace?
|
||||
*
|
||||
*/
|
||||
struct SpaceInfo
|
||||
{
|
||||
bool inited;
|
||||
|
@ -114,6 +120,46 @@ static size_t space_reqid = 0;
|
|||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
struct SpaceKey
|
||||
{
|
||||
PT::Space * global_space;
|
||||
std::vector<std::wstring> spaces_names;
|
||||
|
||||
|
||||
bool operator<(const SpaceKey & k)
|
||||
{
|
||||
if( global_space != k.global_space )
|
||||
return global_space < k.global_space;
|
||||
|
||||
if( spaces_names.size() != k.spaces_names.size() )
|
||||
return spaces_names.size() < k.spaces_names.size();
|
||||
|
||||
for(size_t i=0 ; i<spaces_names.size() ; ++i)
|
||||
{
|
||||
if( spaces_names[i] != k.spaces_names[i] )
|
||||
return spaces_names[i] < k.spaces_names[i];
|
||||
}
|
||||
|
||||
|
||||
* this is the same space
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* mapping a global space with spaces names (strings) to a last space address
|
||||
*/
|
||||
//static std::map<SpaceKey, PT::Space *> space_map;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void space_init(const std::vector<Ezc::Var> & params, PT::Space & space, SpaceInfo & space_info)
|
||||
{
|
||||
if( !space_info.inited || !are_spaces_the_same(params, space_info.spaces) )
|
||||
|
@ -122,11 +168,6 @@ void space_init(const std::vector<Ezc::Var> & params, PT::Space & space, SpaceIn
|
|||
copy_space(params, space_info.spaces);
|
||||
space_info.last_space = find_space(params, space);
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! temp
|
||||
//log << log1 << "taking space from the cache" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,7 +181,7 @@ void space_check_reqid()
|
|||
}
|
||||
|
||||
|
||||
void space(Info & i, PT::Space & space)
|
||||
void space_value(Info & i, PT::Space & space, bool escape)
|
||||
{
|
||||
space_check_reqid();
|
||||
|
||||
|
@ -155,34 +196,18 @@ void space(Info & i, PT::Space & space)
|
|||
const std::wstring * value = space_info.last_space->GetValue(param);
|
||||
|
||||
if( value )
|
||||
i.out << *value;
|
||||
// else
|
||||
// log << log1 << "nie ma takiej wartosci" << logend; // only for testing
|
||||
// !! IMPROVE ME
|
||||
{
|
||||
if( escape )
|
||||
i.out << *value;
|
||||
else
|
||||
i.out << R(*value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void space_value_noescape(Info & i, PT::Space & space)
|
||||
{
|
||||
space_check_reqid();
|
||||
|
||||
if( !i.params.empty() )
|
||||
{
|
||||
SpaceInfo & space_info = spaces_map[&space];
|
||||
space_init(i.params, space, space_info);
|
||||
|
||||
if( space_info.last_space )
|
||||
{
|
||||
const std::wstring & param = i.params.back().str;
|
||||
const std::wstring * value = space_info.last_space->GetValue(param);
|
||||
|
||||
if( value )
|
||||
i.out << R(*value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -299,7 +324,7 @@ void spaces_tab_init(std::vector<Ezc::Var> & params, PT::Space & space, SpacesTa
|
|||
|
||||
|
||||
|
||||
void spaces_tab(Info & i, PT::Space & space)
|
||||
void space_list_tab(Info & i, PT::Space & space)
|
||||
{
|
||||
spaces_tab_check_reqid();
|
||||
|
||||
|
@ -340,7 +365,7 @@ void spaces_tab_value_print(HtmlTextStream & out, SpacesTabInfo & spaces_tab_inf
|
|||
}
|
||||
|
||||
|
||||
void spaces_tab_value(Info & i, PT::Space & space)
|
||||
void space_list_tab_value(Info & i, PT::Space & space)
|
||||
{
|
||||
spaces_tab_check_reqid();
|
||||
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
|
||||
|
@ -374,7 +399,7 @@ return false;
|
|||
}
|
||||
|
||||
|
||||
void spaces_tab_has_next(Info & i, PT::Space & space)
|
||||
void space_list_tab_has_next(Info & i, PT::Space & space)
|
||||
{
|
||||
spaces_tab_check_reqid();
|
||||
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012-2014, Tomasz Sowa
|
||||
* Copyright (c) 2012-2016, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -37,24 +37,52 @@
|
|||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace TemplatesFunctions
|
||||
{
|
||||
|
||||
// !! rename to 'space_value'
|
||||
void space(Info & i, PT::Space & space);
|
||||
void space_value_noescape(Info & i, PT::Space & space);
|
||||
|
||||
// !! rename to 'space_value_tab' etc.
|
||||
void spaces_tab(Info & i, PT::Space & space);
|
||||
void spaces_tab_value(Info & i, PT::Space & space);
|
||||
void spaces_tab_has_next(Info & i, PT::Space & space);
|
||||
/*
|
||||
* return a value from a space
|
||||
* you can define you own ezc function e.g. my_space_value(Info &i) in such a way:
|
||||
*
|
||||
* void my_space_value(Info & i)
|
||||
* {
|
||||
* space_value(i, the_space_object_i_am_interested_in);
|
||||
* }
|
||||
*
|
||||
* and now you can call it from ezc template:
|
||||
* [my_space_value "foo"] -> looking for parameter "foo" in the global space of the_space_object_i_am_interest_in
|
||||
* [my_space_value "foo" "bar"] -> first looking for a space with "foo" name then looking for "bar" parameter
|
||||
*
|
||||
*
|
||||
* there is some built-in optimization made:
|
||||
* if you are looking for parameters from the same space e.g.
|
||||
* [my_space_value "foo" "foo2" "param1"]
|
||||
* [my_space_value "foo" "foo2" "param2"]
|
||||
* [my_space_value "foo" "foo2" "param3"]
|
||||
* after looking for param1 the address of foo2 space is cached in a local map (first we're looking for foo and then for foo2)
|
||||
* and when looking for param2 and param3 the address of foo2 is taken from the map
|
||||
*
|
||||
*
|
||||
*/
|
||||
void space_value(Info & i, PT::Space & space, bool escape = true);
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// add
|
||||
// void space_list_tab_size(Info & i, PT::Space & space);
|
||||
|
||||
void space_list_tab(Info & i, PT::Space & space);
|
||||
void space_list_tab_value(Info & i, PT::Space & space);
|
||||
void space_list_tab_has_next(Info & i, PT::Space & space);
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// !! add space_tab (iteration through spaces)
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace TemplatesFunctions
|
||||
|
||||
} // namespace Winix
|
||||
|
|
Loading…
Reference in New Issue