changed: the way how raw template is set

option for setting raw template from 'emacs' function has been removed
         now we have index_raw.html template and it can be set from 'template' function
removed: template index_fullscreen.html
changed: some work in miscspace (changed: space_list_tab, space_list_tab_value and space_list_tab_has_next)
fixed:   main index template could not be set through 'template' function





git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1039 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2016-04-04 16:02:36 +00:00
parent abd1500f07
commit 240bf4dc5d
21 changed files with 105 additions and 445 deletions

View File

@@ -120,44 +120,6 @@ 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)
@@ -212,233 +174,20 @@ void space_value(Info & i, PT::Space & space, bool escape)
/*
stack item for [for] statement
*/
struct SpaceStackItem
struct SpaceTabStackItem : public Ezc::FunData
{
// names of the spaces
std::vector<std::wstring> spaces;
// table of values
std::vector<std::wstring> values;
// an index to 'values' which is incremented every each [for]
size_t value_index;
SpaceStackItem()
{
value_index = 0;
}
};
/*
each Space has its own SpacesTabInfo struct
*/
struct SpacesTabInfo
{
// a stack for [for] statements
std::vector<SpaceStackItem> stack_tab;
// current item from 'stack_tab'
size_t cur_stack;
SpacesTabInfo()
{
cur_stack = 0;
}
};
static std::map<PT::Space*, SpacesTabInfo> spaces_tab_info_map;
static size_t spaces_tab_reqid = 0;
bool spaces_tab_find_stack_item(std::vector<Ezc::Var> & params, SpacesTabInfo & spaces_tab_info)
{
bool found = false;
spaces_tab_info.cur_stack = spaces_tab_info.stack_tab.size();
for(size_t i=0 ; i<spaces_tab_info.stack_tab.size() ; ++i)
{
if( are_spaces_the_same(params, spaces_tab_info.stack_tab[i].spaces) )
{
spaces_tab_info.cur_stack = i;
found = true;
break;
}
}
return found;
}
void spaces_tab_add_to_stack(std::vector<Ezc::Var> & params, PT::Space & space, SpacesTabInfo & spaces_tab_info)
{
if( !params.empty() )
{
// adding a new item at the end (with the default constructor)
spaces_tab_info.stack_tab.resize(spaces_tab_info.stack_tab.size() + 1);
spaces_tab_info.cur_stack = spaces_tab_info.stack_tab.size() - 1;
SpaceStackItem & stack_item = spaces_tab_info.stack_tab.back();
copy_space(params, stack_item.spaces);
space.ListText(params.back().str, stack_item.values);
stack_item.value_index = 0;
}
}
void spaces_tab_check_reqid()
{
if( spaces_tab_reqid != cur->request->id )
{
spaces_tab_reqid = cur->request->id;
spaces_tab_info_map.clear();
}
}
void spaces_tab_init(std::vector<Ezc::Var> & params, PT::Space & space, SpacesTabInfo & spaces_tab_info)
{
PT::Space * child_space = find_space(params, space);
if( child_space )
{
if( !spaces_tab_find_stack_item(params, spaces_tab_info) )
{
// add a new value to the stack
spaces_tab_add_to_stack(params, *child_space, spaces_tab_info);
}
}
else
{
// there is not such a space
// space_list_tab() will return false immediately
spaces_tab_info.cur_stack = spaces_tab_info.stack_tab.size();
}
}
void space_list_tab(Info & i, PT::Space & space)
{
spaces_tab_check_reqid();
if( !i.params.empty() )
{
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
spaces_tab_init(i.params, space, spaces_tab_info);
if( spaces_tab_info.cur_stack < spaces_tab_info.stack_tab.size() )
{
SpaceStackItem & stack_item = spaces_tab_info.stack_tab[spaces_tab_info.cur_stack];
// i.iter is different for each [for] statement (implemented in EZC)
// so we don't have to remember it in our stack
// for each the same space we have only one item in the stack, e.g.
// [for item_meta "space1" "space2" "value"]
// [for item_meta "space1" "space2" "value"]
// [end]
// [end]
// above two [for]s use the same item on our stack
stack_item.value_index = i.iter;
i.res = stack_item.value_index < stack_item.values.size();
}
}
}
void spaces_tab_value_print(HtmlTextStream & out, SpacesTabInfo & spaces_tab_info)
{
if( spaces_tab_info.cur_stack < spaces_tab_info.stack_tab.size() )
{
SpaceStackItem & stack_item = spaces_tab_info.stack_tab[spaces_tab_info.cur_stack];
if( stack_item.value_index < stack_item.values.size() )
out << stack_item.values[stack_item.value_index];
}
}
void space_list_tab_value(Info & i, PT::Space & space)
{
spaces_tab_check_reqid();
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
if( i.params.empty() )
{
// value from last [for ...] statement
spaces_tab_value_print(i.out, spaces_tab_info);
}
else
{
size_t cur_stack_old = spaces_tab_info.cur_stack;
if( spaces_tab_find_stack_item(i.params, spaces_tab_info) )
spaces_tab_value_print(i.out, spaces_tab_info);
spaces_tab_info.cur_stack = cur_stack_old;
}
}
bool spaces_tab_has_next(SpacesTabInfo & spaces_tab_info)
{
if( spaces_tab_info.cur_stack < spaces_tab_info.stack_tab.size() )
{
SpaceStackItem & val = spaces_tab_info.stack_tab[spaces_tab_info.cur_stack];
return val.value_index + 1 < val.values.size();
}
return false;
}
void space_list_tab_has_next(Info & i, PT::Space & space)
{
spaces_tab_check_reqid();
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
if( i.params.empty() )
{
// value from last [for ...] statement
i.res = spaces_tab_has_next(spaces_tab_info);
}
else
{
size_t cur_stack_old = spaces_tab_info.cur_stack;
if( spaces_tab_find_stack_item(i.params, spaces_tab_info) )
i.res = spaces_tab_has_next(spaces_tab_info);
spaces_tab_info.cur_stack = cur_stack_old;
}
}
struct Space2StackItem : public Ezc::FunData
{
std::vector<std::wstring> values;
};
void space2_list_tab(Info & i, PT::Space & space)
{
if( !i.stack.fun_data )
{
if( !i.params.empty() )
{
i.stack.for_name = new std::wstring(L"space_list_tab");
Space2StackItem * stack_item = new Space2StackItem();
SpaceTabStackItem * stack_item = new SpaceTabStackItem();
i.stack.fun_data = stack_item;
PT::Space * dst_space = find_space(i.params, space);
@@ -451,27 +200,32 @@ void space2_list_tab(Info & i, PT::Space & space)
}
else
{
auto stack_item = reinterpret_cast<Space2StackItem*>(i.stack.fun_data);
auto stack_item = reinterpret_cast<SpaceTabStackItem*>(i.stack.fun_data);
i.res = i.iter < stack_item->values.size();
}
}
void space2_list_tab_value(Info & i, PT::Space & space)
void space_list_tab_value(Info & i, PT::Space & space, const std::wstring & function_name)
{
Ezc::Stack * stack = i.FindLastFor(i.par, L"space_list_tab");
Ezc::Stack * stack;
auto user_object = i.FindUserObject<SpaceTabStackItem>(function_name, &stack);
if( stack && stack->fun_data )
{
auto stack_item = dynamic_cast<Space2StackItem*>(stack->fun_data);
if( stack_item && stack->iter < stack_item->values.size() )
i.out << stack_item->values[stack->iter];
}
if( user_object && stack->iter < user_object->values.size() )
i.out << user_object->values[stack->iter];
}
void space_list_tab_has_next(Info & i, PT::Space & space, const std::wstring & function_name)
{
Ezc::Stack * stack;
auto user_object = i.FindUserObject<SpaceTabStackItem>(function_name, &stack);
if( user_object && stack->iter + 1 < user_object->values.size() )
i.res = true;
}