Code refactorings (r403:404)

This commit is contained in:
starkos 2008-06-13 13:21:32 +00:00
parent 7907a92a31
commit 839ffcec86
7 changed files with 29 additions and 45 deletions

View File

@ -34,9 +34,10 @@ int gmake_solution_all_rule(Session sess, Solution sln, Stream strm)
assert(sln);
assert(strm);
prj_names = solution_get_project_names(sln);
prj_names = make_get_project_names(sln);
z = stream_writeline_strings(strm, prj_names, "all:", " ", "", "");
z |= stream_writeline(strm, "");
strings_destroy(prj_names);
return z;
}
@ -111,9 +112,10 @@ int gmake_solution_phony_rule(Session sess, Solution sln, Stream strm)
assert(sln);
assert(strm);
prj_names = solution_get_project_names(sln);
prj_names = make_get_project_names(sln);
z = stream_writeline_strings(strm, prj_names, ".PHONY: all clean", " ", "", "");
z |= stream_writeline(strm, "");
strings_destroy(prj_names);
return z;
}

View File

@ -86,6 +86,29 @@ const char* make_get_project_makefile(Session sess, Project prj)
}
/**
* Build a list of project names contained by the solution.
* \param sln The solution to query.
* \returns A list of project names. The caller owns this list and must destroy it when done.
*/
Strings make_get_project_names(Solution sln)
{
Strings result;
int i, n;
result = strings_create();
n = solution_num_projects(sln);
for (i = 0; i < n; ++i)
{
Project prj = solution_get_project(sln, i);
const char* name = project_get_name(prj);
strings_add(result, name);
}
return result;
}
/**
* Get the name of the solution makefile for a particular solution.
* \param sess The current execution session context.

View File

@ -10,6 +10,7 @@
const char* make_get_obj_filename(const char* filename);
const char* make_get_project_makefile(Session sess, Project prj);
Strings make_get_project_names(Solution sln);
const char* make_get_solution_makefile(Session sess, Solution sln);
#endif

View File

@ -3,7 +3,7 @@
* \brief File handling.
* \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
*
* \defgroup dir File Management
* \defgroup file File Management
* \ingroup base
*
* File management functions.

View File

@ -31,7 +31,6 @@ DEFINE_CLASS(Solution)
{
Fields fields;
Array projects;
Strings project_names;
};
@ -44,7 +43,6 @@ Solution solution_create()
Solution sln = ALLOC_CLASS(Solution);
sln->fields = fields_create(SolutionFieldInfo);
sln->projects = array_create();
sln->project_names = NULL;
return sln;
}
@ -68,11 +66,6 @@ void solution_destroy(Solution sln)
}
array_destroy(sln->projects);
if (sln->project_names != NULL)
{
strings_destroy(sln->project_names);
}
free(sln);
}
@ -240,30 +233,6 @@ Project solution_get_project(Solution sln, int index)
}
/**
* Retrieve the names of all projects contained by the solution.
* \param sln The solution to query.
* \returns A list of project names.
*/
Strings solution_get_project_names(Solution sln)
{
assert(sln);
if (sln->project_names == NULL)
{
int i, n;
sln->project_names = strings_create();
n = solution_num_projects(sln);
for (i = 0; i < n; ++i)
{
Project prj = solution_get_project(sln, i);
const char* name = project_get_name(prj);
strings_add(sln->project_names, name);
}
}
return sln->project_names;
}
/**
* Retrieve a string (single value) fields from a solution, using the field indices.
* \param sln The solution object to query.

View File

@ -47,7 +47,6 @@ const char* solution_get_language(Solution sln);
const char* solution_get_location(Solution sln);
const char* solution_get_name(Solution sln);
Project solution_get_project(Solution sln, int index);
Strings solution_get_project_names(Solution sln);
const char* solution_get_value(Solution sln, enum SolutionField field);
int solution_num_configs(Solution sln);
int solution_num_projects(Solution sln);

View File

@ -203,14 +203,4 @@ SUITE(project)
solution_add_project(sln, prj);
CHECK(sln == project_get_solution(prj));
}
TEST_FIXTURE(FxSolution, GetProjectNames_ReturnsNames)
{
Project prj = project_create();
project_set_name(prj, "MyProject");
solution_add_project(sln, prj);
Strings result = solution_get_project_names(sln);
CHECK_EQUAL("MyProject", strings_item(result, 0));
}
}